When developing you will create lots of local git branches. Let’s see how to delete them all in once with this command line :
git branch | grep -v "master" | xargs git branch -D
This will delete all branches except master. If you want to keep other branches (develop, release), you can do it like this :
git branch | grep -v "master\|release\|develop" | xargs git branch -D
If you want to save everything as an alias to be accessible everywhere in your console add this to your .bashrc
file:
alias gbr="git branch | grep -v "master" | xargs git branch -D"
So that when you use gbr
it will clean all local branches except master