git repack: Usage, Options & Common CI Errors
git repack consolidates a repository’s objects into fewer, more efficient packfiles.
Repacking shrinks a bloated repo and speeds up object access. The common -a -d combination rewrites everything into one pack and removes the now-redundant ones.
What it does
git repack creates new packfiles from existing objects, optionally folding all packs into one and deleting the originals, improving delta compression and lookup speed.
Common usage
git repack -a -d
git repack -A -d # keep unreachable objects loose
git repack -a -d --depth=50 --window=250
git repack -d -l # local objects onlyOptions
| Flag | What it does |
|---|---|
| -a | Pack all objects into a single pack |
| -A | Like -a but keep unreachable objects loose |
| -d | Delete redundant packs afterward |
| --depth / --window | Tune delta compression |
| -l | Pack only local objects (skip alternates) |
Common errors in CI
fatal: Out of memory during delta compression on huge repos - lower --window/--depth or pack.threads, and ensure enough free disk for the new pack to be written before the old ones are deleted. Running repack -d while another git process reads the repo can race; serialize it.
Using this in CI
CI checkouts are shallow and detached by default, which changes the answer this command gives you. Commands that read history, branch names, or tags need the checkout configured for it.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # history, tags, and git describe all need this
- run: |
git rev-parse --is-shallow-repository # expect false
git rev-parse --abbrev-ref HEAD # prints HEAD when detached