Packfile basics
A packfile bundles many objects into one file with delta compression — instead of storing each version of a file in full, similar objects share a base and store only the difference. The result is a 5x to 50x size reduction on real repos. Pack files live under .git/objects/pack/ as pack-<sha>.pack with sidecar .idx and (newer) .rev files.
Inspecting packs
git verify-pack -v .git/objects/pack/pack-*.idx | head
git count-objects -v
git cat-file --batch-all-objects --batch-check='%(objectname) %(objecttype) %(objectsize:disk)'
The verify output shows each object's type, size on disk, and (if delta) base object and depth.
Repacking
Repack to consolidate loose objects and rebuild deltas:
git repack -ad # full repack, drop redundant
git repack -adf --depth=50 --window=250
git repack --geometric=2 -d # geometric repack (Git 2.32+)
--window controls how many objects are considered as delta bases for each candidate; larger windows produce smaller packs at the cost of CPU.
Geometric repacking
Geometric repacking (Git 2.32+) keeps a series of pack sizes in a 1:N ratio, avoiding the cost of repacking everything every time. See "Geometric repacking strategy".
Multi-pack-index
With many packs, lookups slow down. The MIDX file (Git 2.20+, on by default in modern installs) provides a unified index across packs:
git multi-pack-index write
git multi-pack-index verify
See "Multi-pack-index (MIDX): unified pack object lookup".
Delta tuning
[pack]
windowMemory = 256m
threads = 0 # auto-detect cores
deltaCacheSize = 256m
For huge repos, increase pack.windowMemory. pack.threads = 0 uses all available cores. See "pack.windowMemory and pack.threads tuning".
Reachability bitmaps
Bitmap indexes (.bitmap files) accelerate counts of reachable objects, used by git clone, git fetch, and gc. Generate with:
git repack -adb
See "Reachability bitmaps for fast set operations".
Common mistakes
Manually deleting pack files — Git tracks them in metadata; use git repack. Setting pack.window very high without pack.windowMemory can OOM the box. Forgetting that git gc --aggressive recomputes deltas with depth 250 and window 250, which is heavy; reserve for occasional maintenance.
Related
See "Geometric repacking strategy", "Reachability bitmaps for fast set operations", and "Background maintenance: git maintenance run/start/stop".