Git Reference ยท Maintenance and Recovery
git pack-refs command
Reference for git pack-refs: how it moves loose branch and tag files into the single packed-refs file, what --all and --prune do, and when Git runs it for you.
Every branch and tag is normally stored as a tiny file under .git/refs/, holding one object ID. That is simple, but a repository with tens of thousands of tags ends up with tens of thousands of small files, which is slow to scan on most file systems. git pack-refs copies those refs into one text file, .git/packed-refs, and (with --prune, the default) deletes the loose files.
Packing is invisible to everyday commands. When a ref exists both as a loose file and in packed-refs, the loose file wins, so a branch that moves again simply becomes loose again. git gc calls pack-refs for you, so you rarely need it by hand.
git pack-refs [--all] [--no-prune]
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git pack-refs [--all] [--no-prune] [--include <pattern>] [--exclude <pattern>]
| Name | Description |
|---|---|
| (no option) | Pack all tags that are already packed, plus all annotated tags and the refs that are already in packed-refs. Loose branch heads are left alone. |
--all |
Pack every ref under refs/, including branches. This is what git gc uses. |
--no-prune |
Write packed-refs but keep the loose ref files. |
--include <pattern> |
Pack refs that match the pattern in addition to the default set. May be repeated. |
--exclude <pattern> |
Do not pack refs that match the pattern, even when --all is given. |
Returns: nothing on success, exit status 0.
Edge cases: the command takes a lock on packed-refs; if another process holds it, the command fails with a "Unable to create ... packed-refs.lock" error and you can retry. Repositories using the reftable backend (git init --ref-format=reftable) do not have a packed-refs file, and pack-refs then compacts the reftable stack instead.
Usage notes
- The file format.
packed-refsbegins with a header comment line, then one line per ref: the object ID, a space and the ref name. After an annotated tag a line starting with^holds the commit the tag finally points to (the peeled value), which makes tag lookups fast. See The packed-refs file. - Loose wins. If a ref is both packed and loose, the loose value is used. Do not edit
packed-refsby hand to move a ref that still has a loose file. - Deleting packed refs.
git branch -dandgit tag -dremove the entry frompacked-refstoo, rewriting the file. Many deletions at once are slow with a huge file; usegit update-ref --stdinto batch them. - When it pays off. Thousands of refs, networked or antivirus-scanned file systems, and servers that advertise all refs on every fetch. For a normal project with a few dozen branches the effect is negligible.
- Safe to run anytime. The operation only changes how refs are stored, never what they point to. It does not touch objects.
- Not the same as
gc.pack-refshandles refs only. Objects are packed by git repack.