Synopsis
git repack [-a] [-d] [-l] [--depth=<n>] [--window=<n>]
Description
The git repack command repackages the repository's objects, combining multiple packs into one and optionally moving loose objects into packs. It's the primary way Git stays compact. git gc calls repack as part of its work; manual repack exposes finer control over delta search parameters.
In day-to-day use, git repack integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git repack --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git repack interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git repack's side effects helps avoid all three.
When to Use
Most users rely on gc. Reach for repack directly when tuning storage on a server (large repos benefit from custom --depth, --window) or when investigating storage layout.
Common Options
| Option | Description |
|---|---|
-a | Pack everything reachable into a single pack. |
-A | Like -a but keep unreachables loose. |
-d | Delete redundant packs after repacking. |
-l | Pass --local to pack-objects. |
--depth=<n> | Maximum delta chain depth. |
--window=<n> | Window size for delta selection. |
-k, --keep-pack=<name> | Keep the named pack untouched. |
Examples
git repack -ad
# Single pack, drop redundant ones
git repack -a -d --depth=50 --window=250
# Tighter packing for storage savings (slower)
git repack -A -d
# Keep unreachables loose for safety
Common Mistakes
Aggressive parameters consume RAM and CPU disproportionate to space saved. Default values are tuned reasonably. Forgetting -d after -a leaves duplicate packs.
Related Commands
git gc, git pack-objects, git verify-pack, git prune