git gc
git
Usage
git gc [--aggressive] [--prune=<date>]Packs loose objects and drops unreachable ones to shrink .git; --prune=now also throws away the commits the reflog was holding, which removes your safety net for undoing a reset.
Common flags
| Flag | Meaning |
|---|---|
| --aggressive | repack harder; slow, occasionally worth it |
| --prune=<date> | drop unreachable objects older than that |
| --prune=now | drop them all, which also throws away reflog-only commits |
| --auto | do nothing unless there is enough loose junk |
| --no-prune | repack but keep unreachable objects |
| -q | no progress output |
Examples
git gcpacks loose objects and shrinks .git
git gc --autothe cheap check git itself runs after some commands
git gc --prune=now --aggressivesmallest result, and no way back to lost commits
The confusion is that undo has several shapes — moving where a branch points is not the same as adding a commit that reverses it.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does git gc do?
Packs loose objects and drops unreachable ones to shrink .git; --prune=now also throws away the commits the reflog was holding, which removes your safety net for undoing a reset.
Q. How do I type it?
git gc [--aggressive] [--prune=<date>] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man git. This command sits under git.
Related commands
man page: man git-gc