git-prune
Remove unreachable Git objects
TLDR
Report what would be removed by Git prune without removing it
Prune unreachable objects and display what has been pruned to stdout
Prune unreachable objects while showing progress
SYNOPSIS
git prune [--expire=
PARAMETERS
--expire=
Prunes objects older than the specified
DESCRIPTION
git prune is a low-level plumbing command that cleans up the object database by removing objects that are no longer reachable from any of your refs (branches, tags, HEAD, remote-tracking branches, etc.). These unreachable objects are often created during operations like rebasing, amending commits, or resetting, where original commits become unreferenced.
By default, git prune only removes objects that are older than two weeks, providing a safety margin. This command is typically invoked by git gc (garbage collection) to keep the repository tidy and efficient. Running git prune can help reduce the size of your repository, especially after operations that create many temporary or unreferenced objects. It's important to understand that git prune only removes unreachable objects; it will never remove objects that are part of your history, even if they are very old.
CAVEATS
git prune only removes unreachable objects. It will not remove objects that are part of reachable history, even if they are very old or seem unnecessary.
By default, objects less than two weeks old are not pruned, providing a safety net. Use --expire=now (or --expire=0) to prune all unreachable objects immediately.
Once an object is pruned, it is permanently gone unless it exists in another repository or a backup. There is no 'undo' for git prune.
It's a 'plumbing' command; most users interact with git gc which calls git prune internally.
OBJECT REACHABILITY
git prune operates on the concept of object reachability. An object is considered reachable if it can be found by traversing the commit graph starting from any ref (branches, tags, HEAD, remote-tracking branches, reflogs). Objects not reachable by this process are considered 'dangling' or 'unreachable' and are candidates for pruning.
PLUMBING COMMAND
git prune is classified as a 'plumbing' command in Git. Plumbing commands are low-level commands designed to be used by other Git commands or by scripts, rather than directly by end-users. This distinguishes them from 'porcelain' commands (like git add, git commit, git status) which are user-friendly.
HISTORY
git prune has been a fundamental part of Git's object management system since its early days. It's a core component of how Git maintains its repository efficiency by cleaning up unreachable objects. While users typically interact with git gc for repository maintenance, git prune serves as the underlying mechanism for removing these objects, demonstrating Git's modular design where complex operations are built upon simpler, focused tools. Its default 2-week expiry period has been a long-standing safety feature.
SEE ALSO
git gc(1), git reflog(1), git fsck(1)