git gc

Administration

Clean up and optimize the repository


The 'git gc' command (garbage collection) packs loose objects into compressed packfiles, removes objects nothing refers to any more (after their grace period), and tidies references and reflogs. Git runs a light version automatically; you rarely need it by hand. It changes storage only — never your commits, branches or files.

Synopsis

git gc [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]
[ ] optional| or<arg> placeholder... repeatable--flag option

Examples

Tidy up

git gc

Pack and clean.


Remove unreachable objects now

git gc --prune=now

Also deletes lost commits immediately (careful).

Workflow Examples

1
git reflog expire --expire=now --all

Forget old positions

2
git gc --prune=now --aggressive

Delete and repack

Troubleshooting

Auto packing the repository… message

Cause: Git ran gc automatically

Nothing to do; it keeps the repository fast

Tips & Pitfalls

Best Practices

  • ✓Let Git run it automatically, or schedule git maintenance.

Common Mistakes

  • ✗Running git gc --prune=now while hoping to recover a lost commit — it deletes it.

FAQ

A:

Only unreachable objects older than the grace period (2 weeks by default); reachable commits are never touched.