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: prune remote tracking references deleted on GitHub/GitLab, list all branches merged into your current branch (e.g. main), then delete those merged local branches safely, excluding main, master, and develop:
git remote prune origin
git branch --merged
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 (see error: The branch 'x' is not fully merged). To find stale branches, sort local branches by last 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.