What does git gc actually do, and what is the role of prune and repack?

Last updated 6 July 2026

  • git gc cleans up the repo: it repacks, prunes, packs refs, expires reflogs, and rebuilds the commit-graph (often auto-triggered via gc.auto).

  • prune deletes unreachable objects older than a grace period (default 2 weeks) to avoid racing concurrent operations.

  • repack merges loose objects and packs into fewer delta-compressed packfiles, saving space and speeding lookups.

  • https://www.geeksforgeeks.org/git/git-gc-garbage-collection/
  • https://git-scm.com/docs/git-repack
  • https://git-scm.com/docs/git-gc
  • https://support.atlassian.com/bitbucket-data-center/kb/understanding-git-repack-and-git-prune-options-in-bitbucket-data-center/
  • https://www.kernel.org/pub/software/scm/git/docs/git-prune.html
  • https://github.blog/engineering/architecture-optimization/scaling-gits-garbage-collection/
  • https://www.atlassian.com/git/tutorials/git-gc
All Git interview questions