Progress:
TIER 2 · MODULE 11· Intermediate

git repack

Loose objects in, packfiles out.

🎯 What & why

git repack consolidates loose objects and existing packfiles into fewer, denser packs. It's the heavy lifter that git gc calls under the hood.

🧠 Mental model

Loose objects are one file per object — fast to write, slow to read at scale. Packs are delta-compressed archives with an index. Repack trades CPU now for I/O savings forever.

🛠️ Synopsis

git repack [-a] [-A] [-d] [-l] [-f]
          [--max-pack-size=<n>] [--depth=<n>] [--window=<n>]
          [--keep-pack=<name>] [--write-bitmap-index]

🎚️ Switches & options

FlagWhat it does
-aPack all reachable objects into a single new pack. Without this, you only repack loose objects.
-ALike -a but unreachable objects are exploded back to loose instead of dropped — gives gc a chance to expire them.
-dDelete redundant packs after repacking. Without -d you accumulate cruft.
-lUse only local packs; skip alternates. Important when working with shared object stores.
--max-pack-size=<n>Cap pack file size (e.g. 2g). Useful for filesystems that hate huge files.
--depth=<n>Max delta chain length. Default 50; larger = smaller packs, slower reads.
--window=<n>How many neighboring objects to consider for delta candidates. Default 10; larger = better compression, slower repack.
--write-bitmap-indexGenerate a .bitmap file. Massive speedup for clone and fetch on the server side.
-f⚠️ Force re-deltification of all objects. Throws away existing deltas — only use after changing --depth/--window.

💡 Use cases

🧪 Examples

The standard incantation
git repack -ad
Server-grade repack with bitmaps
git repack -adf --write-bitmap-index --depth=50 --window=250
Local-only, ignore alternates
git repack -adl
Cap pack size at 2GB
git repack -ad --max-pack-size=2g

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.