Usually invoked indirectly by gc.
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/.
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.
git prune [-n|--dry-run] [-v|--verbose] [--progress]
[--expire <time>] [--exclude-promisor-objects] [--] [<head>...]| Flag | What it does |
|---|---|
-n, --dry-run | Show what would be pruned. Run this first. Always. |
-v, --verbose | Print each object as it's pruned. |
--expire <time> | Only prune objects older than <time>. Default: 2 weeks (gc.pruneExpire). |
--exclude-promisor-objects | Don't prune objects from a promisor remote (partial clone). You want this if you partial-cloned. |
--progress | Show 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. |
filter-repo or filter-branch rewrite, to actually shrink the repo.gc regularly.git gc calls it for you with sane defaults.git prune --dry-run --verbosegit gcgit reflog expire --expire-unreachable=now --all
git gc --prune=nowgit prune --exclude-promisor-objectsgit gc over git prune. gc packs first, then prunes — pruning unpacked-from objects you didn't pack first is wasted work.gc for at least 14 days. Respect it.prune --expire=now runs, the reflog won't save you.git prune does NOT touch packed objects. To shrink those, you need git repack -ad (which gc does).prune --expire=now after reflog expire --expire-unreachable=now is irreversible. If you got here by accident, there's no Ctrl+Z.--exclude-promisor-objects can prune objects the remote expects you to have. Refetch country.Hit each option, then Check answers. Score is recorded; Next is always open.