Synopsis
git pack-objects [--stdout] [--all] <base-name> < <object-list>
Description
The git pack-objects command compresses a set of objects into a single packfile, applying delta compression to similar objects. Packs are how Git stores objects efficiently on disk and over the network — every fetch and push transfers packs.
In day-to-day use, git pack-objects 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 pack-objects --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 pack-objects 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 pack-objects's side effects helps avoid all three.
When to Use
You almost never invoke this directly. git gc, git repack, and the network protocol drive it for you. Reach for it manually when implementing custom transport, optimizing storage, or experimenting with delta strategies.
Common Options
| Option | Description |
|---|---|
--stdout | Write the pack to stdout instead of files. |
--all | Pack everything reachable from any ref. |
--revs | Read revisions from stdin instead of object SHAs. |
--depth=<n> | Maximum delta chain depth. |
--window=<n> | Window size for delta search. |
--thin | Allow thin packs (deltas against external objects). |
--no-reuse-delta | Recompute deltas instead of reusing existing. |
Examples
git rev-list --objects --all | git pack-objects --stdout > everything.pack
# Build a single pack of every reachable object
git rev-list --objects HEAD ^origin/main | \
git pack-objects --thin --stdout > ahead.pack
# A thin pack of just the commits ahead of origin/main
git pack-objects --all .git/objects/pack/extra
# Repack all reachable objects into a new pack named "extra"
Common Mistakes
Building large packs with --depth and --window set too high consumes lots of memory and CPU. The defaults from git gc are sensible for most repos. Producing thin packs without context (an existing repo to apply them to) is useless.
Related Commands
git unpack-objects, git verify-pack, git gc, git repack