git gc: Usage, Options & Common CI Errors
git gc (garbage collect) packs loose objects and prunes unreachable ones to keep the repository tidy.
gc reclaims space and speeds up operations. Git runs it automatically, but you can invoke it directly.
What it does
git gc packs loose objects into packfiles, removes redundant objects, prunes unreachable objects past the grace period, and packs refs to optimize the repository.
Common usage
Terminal
git gc
git gc --aggressive # slower, better compression
git gc --prune=now # prune immediately
git gc --auto # only if thresholds are exceededOptions
| Flag | What it does |
|---|---|
| --aggressive | Recompute deltas for tighter packing |
| --prune=<date> | Prune unreachable objects older than date |
| --auto | Run only when needed (used internally) |
| --no-prune | Do not prune any objects |
Common errors in CI
fatal: gc is already running on machine … / "Unable to create '.git/gc.pid.lock': File exists" - a stale lock from a killed process. Remove .git/gc.pid.lock if no gc is actually running. Aggressive gc is slow; avoid it in time-boxed CI steps.
Related guides
git fsck: Usage, Options & Common CI Errorsgit fsck verifies object-database integrity and finds dangling or corrupt objects. Reference for --full, --lo…
git reflog: Usage, Options & Common CI Errorsgit reflog records where HEAD and branches have been, so you can recover lost commits. Reference for show, ex…
git clone: Usage, Options & Common CI Errorsgit clone copies a remote repository into a new local directory. Reference for depth, branch, and submodule f…
git cat-file: Usage, Options & Common CI Errorsgit cat-file inspects Git objects - their type, size, and content. Reference for -t, -s, -p, --batch, and the…