List local stale branches:
git branch -vv | grep 'gone' | awk '{print $1}'List and delete local stale branches
git branch -vv | grep "gone" | awk '{print $1}' | xargs git branch --deleteYou could even create an alias on your machine. Modify ~/.gitconfig (user level, not repo):
[alias]
stale-local-branches = "!git branch -vv | grep 'gone' | awk '{print $1}'"
delete-stale-local = "!git stale-local-branches | xargs git branch -D"Before running any of the two aliases, make sure you run git fetch --prune to sync origin branches deletion.
- List state local branches:
git fetch --prune && stale-local-branches
- Delete state local branches:
git fetch --prune && delete-stale-local