Skip to content
LatchkeyLatchkey home

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

Terminal
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 only

Options

FlagWhat it does
-aPack all objects into a single pack
-ALike -a but keep unreachable objects loose
-dDelete redundant packs afterward
--depth / --windowTune delta compression
-lPack 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.

.github/workflows/ci.yml
- 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

Frequently asked questions

git repack: Usage, Options & Common CI Errors?
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 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.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card