Using the git prune command

Kenny DuMez
Kenny DuMez
Graphite software engineer

This guide will provide a comprehensive overview of the git prune command, its use cases, and related commands for pruning in Git.

The git prune command is used to remove unreachable objects from the .git directory, which are objects that are no longer accessible from any of the references in the repository. These could be old commits, unused blobs, or other data that's no longer referenced in any branch, tag, or other reference. Running git prune helps to optimize the repository by cleaning up these leftovers, reducing clutter and reclaiming disk space.

To understand git prune, let’s first look at the basic usage:

git prune

This command is typically used internally by Git, and is run as part of the routine garbage collection protocol.

While the git prune command itself has limited options, its functionality can be leveraged through other Git commands, like fetch and branch.

git fetch combined with the --prune option is a common way to not only update the local references with the remote but also to clean up any remote-tracking branches that no longer exist on the remote repository:

git fetch --prune

Or for a specific remote:

git fetch origin --prune

This command updates your local repository’s remote-tracking branches to reflect the current state of the remote and removes the local remote-tracking branches that have been deleted on the remote.

Remember, git fetch --prune only affects remote-tracking branches. To delete non-tracking local branches see this guide on deleting Git branches.

For further information see the official Git documentation.

Stay unblocked. Ship faster.
Experience the new developer workflow - create, review, and merge code continuously. Get started with one command.
Get started

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2