Skip to content

Git Garbage Collection

Medium — good to knowGit & Version Control

ELI5 - The Vibe Check

Git garbage collection is spring cleaning for your repository. Over time you accumulate loose objects from commits that got amended, rebased away, or abandoned entirely, cluttering up .git with data nobody references anymore. Running git gc sweeps through, packs the objects you still need into efficient packfiles, and eventually lets the truly unreachable ones expire and get deleted, once the reflog stops holding onto them for safety.

Real Talk

git gc performs housekeeping on a local repository: it packs loose objects into packfiles, prunes objects no longer reachable from any ref that have aged past the reflog expiration window, and optimizes internal data structures. It runs automatically in the background under normal usage via git gc --auto and can also be run manually, though running it aggressively right after a risky rebase or reset can prematurely remove objects you might still want to recover via the reflog.

When You'll Hear This

"Run git gc if the .git folder is bloating the whole repo." / "Don't gc --aggressive right after a bad rebase, you might still need the reflog."

Made with passive-aggressive love by manoga.digital. Powered by Claude.