Clean up dangling objects and recompress packfiles.
Garbage-collect unreachable objects, repack loose ones into packfiles, expire reflog entries, prune dangling refs. Keeps the repo small and fast.
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.
git gc [--aggressive] [--auto] [--[no-]detach] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack]| Flag | What it does |
|---|---|
--auto | Run only if needed (e.g. too many loose objects). |
--aggressive | Spend more CPU for better packing. Rarely needed; gc is already good. |
--prune=<date> | Prune objects older than <date> (default: 2 weeks). |
--force | Run even if another gc is in progress. |
filter-repo operations.$ git gc --auto$ git gc --aggressivegit gc --auto handle most cases. Manual gc is rarely the right tool.--aggressive reflexively. It rarely helps and takes a long time.Hit each option, then Check answers. Score is recorded; Next is always open.