Pruning Stale Local Branches

til
git
snippet
Tidy up local branches that no longer exist on remote.
Published

January 11, 2026

Git branches being pruned

After a while, local branches pile up—especially ones tracking remotes that have since been deleted. Here’s how to clean house.

Prune and find stale branches

# Prune stale remote-tracking references
git fetch --prune

# List local branches with gone remotes
git branch -vv | grep ': gone]'

Get just the branch names

git branch -vv | grep ': gone]' | awk '{print $1}'

Delete them all at once

git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -d

Use -D instead of -d to force-delete branches with unmerged changes.