Progress:
TIER 1 · MODULE 41· Basics

git gc

Clean up dangling objects and recompress packfiles.

🎯 What & why

Garbage-collect unreachable objects, repack loose ones into packfiles, expire reflog entries, prune dangling refs. Keeps the repo small and fast.

🧠 Mental model

GC runs repack (loose → pack), then prune (drops unreachable objects older than the prune horizon), then expires the reflog. Reachability is computed by walking from every ref in refs/. Anything not reachable and older than two weeks (default) is fair game.

🛠️ Synopsis

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

🎚️ Switches & options

FlagWhat it does
--autoRun only if needed (e.g. too many loose objects).
--aggressiveSpend more CPU for better packing. Rarely needed; gc is already good.
--prune=<date>Prune objects older than <date> (default: 2 weeks).
--forceRun even if another gc is in progress.

💡 Use cases

🧪 Examples

Standard auto-gc.
$ git gc --auto
Aggressive pack (slow).
$ git gc --aggressive

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.