Interview Prep/Git & GitHub/Git internals: objects, refs and the index

What does `git gc` do, and when does it run automatically?

IntermediateConceptGit internals: objects, refs and the index
Answer

It packs loose objects, packs refs, prunes unreachable objects older than gc.pruneExpire (2 weeks), and expires old reflog entries. git gc --auto runs after commands like commit and merge once there are more than about 6700 loose objects or 50 packs. Large teams usually switch to git maintenance for scheduled background tasks.

git maintenance start
git gc --prune=now --aggressive   # rarely needed
All Git & GitHub questions Roadmap: Git & GitHub

More on Git internals: objects, refs and the index