Progress:
TIER 2 · MODULE 06· Intermediate

git pack-refs

Turns hundreds of loose ref files into one. fsck-friendly.

🎯 What & why

git pack-refs collapses loose ref files (.git/refs/heads/foo, .git/refs/tags/v1, ...) into a single packed-refs file. On a repo with thousands of refs, this is the difference between snappy and molasses.

🧠 Mental model

Refs are normally one tiny file per ref. pack-refs is the same idea as packing objects: trade many syscalls for one. Git transparently reads from either location.

🛠️ Synopsis

git pack-refs [--all] [--no-prune] [--auto]

🎚️ Switches & options

FlagWhat it does
--allPack all refs, not just tags. You almost always want this.
--no-pruneKeep loose refs after packing. Default is to delete them.
--prune(Default) delete loose refs once packed. Saves the inodes.
--auto(Git 2.34+) Pack only if heuristics say it's worth it. What gc uses.
--no-prune⚠️ Doubles disk usage for refs and is rarely what you want outside of debugging.

💡 Use cases

🧪 Examples

Pack everything, prune loose copies
git pack-refs --all
What gc runs internally
git pack-refs --all --prune
Inspect the result
cat .git/packed-refs
Keep loose copies (debugging only)
git pack-refs --all --no-prune

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

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