Progress:
TIER 3 · MODULE 12· Expert

git pack-objects

The compression engine behind clone, fetch, push, gc.

🎯 What & why

The compression engine behind clone, fetch, push, and gc. Reads object SHAs on stdin and emits a delta-compressed packfile (and matching .idx) either to disk or to stdout.

🧠 Mental model

pack-objects is where Git turns a set of objects into wire bytes. Every porcelain that ships objects shells out to it; tuning its flags is how you tune clone/fetch performance and disk layout.

🛠️ Synopsis

git pack-objects [options] <base-name> < object-list
git pack-objects --stdout [options] < object-list > pack.pack
# common knobs:
#   --depth=<n> --window=<n> --max-pack-size=<n> --threads=<n>
#   --include-tag --all-progress --write-bitmap-index
#   --keep-pack=<name> --filter=<spec>

🎚️ Switches & options

FlagWhat it does
--stdoutEmit the pack on stdout instead of writing <base-name>.pack/.idx.
--depth=<n>Max delta chain length (default 50); deeper = smaller pack, slower access.
--window=<n>How many candidate objects to consider for delta base (default 10).
--max-pack-size=<n>Split pack into multiple files at this size (e.g. 2g).
--threads=<n>Parallelism for delta search; defaults to pack.threads / cores.
--include-tagInclude any tag that points at an object already in the pack.
--all-progressShow progress for the entire writeout, not just delta search.
--write-bitmap-indexAlso write a .bitmap reachability index next to the pack.
--keep-pack=<name>Treat <name>.pack as 'do not reuse'; force fresh deltas elsewhere.
--filter=<spec>Partial-clone filter (e.g. blob:none, tree:0) to omit objects.

💡 Use cases

🧪 Examples

Pack everything reachable from HEAD to stdout
git rev-list --objects HEAD | git pack-objects --stdout > out.pack
Tight pack with deep deltas and a bitmap
git rev-list --all --objects | git pack-objects --depth=250 --window=250 --write-bitmap-index pack/all
Cap pack size at 2 GiB and parallelise
git rev-list --all --objects | git pack-objects --max-pack-size=2g --threads=8 pack/split
Blobless partial-clone pack
git rev-list --all --objects | git pack-objects --filter=blob:none --stdout > blobless.pack

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

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