English ▾ Topics ▾ Version 2.21.0 ▾ git-gc last updated in 2.23.0


git-gc - Cleanup unnecessary files and optimize the local repository


git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]


Runs a number of housekeeping tasks within the current repository, such as compressing file revisions (to reduce disk space and increase performance), removing unreachable objects which may have been created from prior invocations of git add, packing refs, pruning reflog, rerere metadata or stale working trees. May also update ancillary indexes such as the commit-graph.



$ git config --global 0





With this option, git gc checks whether any housekeeping is required; if not, it exits without performing any work. Some git commands run git gc --auto after performing operations that could create many loose objects. Housekeeping is required if there are too many loose objects or too many packs in the repository.


If the number of packs exceeds the value of gc.autoPackLimit, then existing packs (except those marked with a .keep file or over gc.bigPackThreshold limit) are consolidated into a single pack by using the -A option of git repack. If the amount of memory is estimated not enough for git repack to run smoothly and gc.bigPackThreshold is not set, the largest pack will also be excluded (this is the equivalent of running git gc with --keep-base-pack). Setting gc.autoPackLimit to 0 disables automatic consolidation of packs.

If houskeeping is required due to many loose objects or packs, all other housekeeping tasks (e.g. rerere, working trees, reflog…​) will be performed as well.




Do not prune any loose objects.


Suppress all progress reports.




All packs except the largest pack and those marked with a .keep files are consolidated into a single pack. When this option is used, gc.bigPackThreshold is ignored.





[gc "refs/remotes/*"]
	reflogExpire = never
	reflogExpireUnreachable = 3 days




The optional configuration variable gc.writeCommitGraph determines if git gc should run git commit-graph write. This can be set to a boolean value. This defaults to false.

The optional configuration variable gc.aggressiveWindow controls how much time is spent optimizing the delta compression of the objects in the repository when the --aggressive option is specified. The larger the value, the more time is spent optimizing the delta compression. See the documentation for the --window option in git-repack[1] for more details. This defaults to 250.



Optional configuration variable gc.worktreePruneExpire controls how old a stale working tree should be before git worktree prune deletes it. Default is "3 months ago".










Part of the git[1] suite