How to Delete All Non Main Git Branches
I like to keep a tidy git repo, so every once in a while when I come to a good stopping point I clean up my local branches. This one liner does not check the merge status, so be careful! You can change the branch names if you have other important branches to exclude.
git branch | egrep -v "(^\*|master|main|dev)" | xargs git branch -D # cleanup git branches
That's all!
The #
at the end is a bash comment. It allows you to search for this command
in your history using keywords!