Read Anthropic’s case study about Graphite Reviewer

Using the git prune command

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


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:

Terminal
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:

Terminal
git fetch --prune

Or for a specific remote:

Terminal
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.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2