Skip to content
Latchkey

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 exceeded

Options

FlagWhat it does
--aggressiveRecompute deltas for tighter packing
--prune=<date>Prune unreachable objects older than date
--autoRun only when needed (used internally)
--no-pruneDo 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

Run this faster and cheaper on Latchkey managed runners. Start free →