Git Developer Guide
How to find and delete stale local Git branches
The Command Line Solution
Over months of development, local repositories accumulate dozens of merged feature branches. Here is how to clean them up from the terminal:
# 1. Prune remote tracking references deleted on GitHub/GitLab
git remote prune origin
# 2. List all branches merged into your current branch (e.g. main)
git branch --merged
# 3. Delete merged local branches safely (excluding main, master, develop)
git branch --merged | grep -vE '^\*|main|master|develop' | xargs -n 1 git branch -d
What about unmerged abandoned branches?
If a branch was squash-merged on GitHub, git branch --merged will not recognize it because the commit hashes differ. To find stale branches by last commit date:
# Sort local branches by commit date
git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
The easier way: GitMon
GitMon automatically flags stale branches that have been merged or untouched for 30+ days across all your repositories. You get a glanceable count in the menu bar without having to run commands in every directory.