Progress:
TIER 2 · MODULE 07· Intermediate

git prune

Usually invoked indirectly by gc.

🎯 What & why

git prune deletes loose objects that no ref (or reflog) can reach. It's how dangling commits, blobs, and trees finally get garbage collected from .git/objects/.

🧠 Mental model

Reachability is the only thing keeping an object alive. Cut every ref and reflog entry pointing at a commit, wait past the prune horizon, and prune will reap it. Until then it's safe.

🛠️ Synopsis

git prune [-n|--dry-run] [-v|--verbose] [--progress]
          [--expire <time>] [--exclude-promisor-objects] [--] [<head>...]

🎚️ Switches & options

FlagWhat it does
-n, --dry-runShow what would be pruned. Run this first. Always.
-v, --verbosePrint each object as it's pruned.
--expire <time>Only prune objects older than <time>. Default: 2 weeks (gc.pruneExpire).
--exclude-promisor-objectsDon't prune objects from a promisor remote (partial clone). You want this if you partial-cloned.
--progressShow a progress meter for big repos.
git prune --expire=now⚠️ Bypasses the safety horizon. If reflogs aren't expired, you can still lose recoverable work.

💡 Use cases

🧪 Examples

See what would die
git prune --dry-run --verbose
Standard cleanup via gc (preferred)
git gc
Aggressive: prune everything unreachable, now
git reflog expire --expire-unreachable=now --all
git gc --prune=now
Partial clone — keep promisor objects
git prune --exclude-promisor-objects

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

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