Pruning Git branches


TL;DR: Delete all local branches merged into master with:

git branch --merged master | grep -v master | xargs git branch -d

List all local branches that are already merged into master:

git branch --merged master

From the list, grep all branches except master:

git branch --merged master | grep -v master

Delete all local branches that have been merged to master:

git branch --merged master | grep -v master | xargs git branch -d

If you want to delete branches merged into dev while excluding master:

git branch --merged dev | grep -v 'master\|dev' | xargs git branch -d

Or:

git branch --merged dev | grep -v -e master -e dev | xargs git branch -d


Please support this site and join our Discord!