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 [-n] [-v] [--progress] [--expire
PARAMETERS
-n, --dry-run
Do not actually remove any objects, just show what would be removed.
-v, --verbose
Report all removed objects.
--progress
Show progress reports on stderr.
--expire
Expire objects older than
DESCRIPTION
The git prune command removes objects from the Git object database that are unreachable, meaning they are not referenced by any branches, tags, or other references.
This helps to reduce the size of the repository by removing orphaned commits, blobs, and trees that are no longer needed.
It operates on loose objects (objects not packed into packfiles).
Usually, this command is run automatically by git gc or called as a post operation hook.
This command is safe to run, as it only removes objects that are truly unreachable. However, caution should be exercised when using custom reflogs or configurations that might affect reachability analysis.
It accepts a timestamp that will prune all the objects older than the specific time. Git prune only remove objects which existed before a certain time, which is by default 2 weeks ago.
CAVEATS
Running git prune on a shared repository can cause issues if other users have not fetched the latest objects. It's generally best to run git gc which includes git prune with appropriate safety measures.
EXPIRATION TIME
The --expire option is crucial for controlling how long unreachable objects are kept before being pruned.
Understanding the default expiry time and adjusting it based on your repository's needs is important to ensure that important objects are not prematurely removed. It can also accept a time expression formatted as YYYY-MM-DD HH:MM:SS which is also supported.
HISTORY
The git prune command has been a part of Git since its early versions. It's a fundamental command for repository maintenance and size optimization. Its development has focused on improving efficiency and ensuring data integrity.
SEE ALSO
git gc(1), git reflog(1), git repack(1)