Sometimes after a sprint, all the remaining branches are just taking up space.
Here’s a small snippet to remove all your local branches in one go.
$ git branch | grep -v "master" | xargs git branch -D
grep -v "master" # will exclude the `master` branch
For an easier reuse you could also alias this useful snippet.
$ echo 'alias gbr="git branch | grep -v "master" | xargs git branch -D"' >> ~/.bash_aliases
Now you only need to type `gbr` to delete all the local branches except `master`
‘>>‘ will append the file with the line above
If you’d like to protect multiple branches then below command could be of help to preserve specific patterns:
git branch | grep -v -e "master" -e "develop" | xargs git branch -D
LikeLiked by 1 person
Thanks buddy
LikeLike