Remove all git branches except master
After working on a project for a while, it’s easy to end up with a lot of legacy branches that are not needed anymore. Removing them one by one would be a cumbersome task. Luckily you don’t have to!
git branch | grep -v "master" | xargs git branch -D
Let me explain each part:
git branch
— list all branchesgrep -v "master"
— removemaster
from the listxargs git branch -D
— executegit branch -D
against remaining branches
So helpful, isn’t it? Catch you next time 👋
Sorry it is not helpful except for Linux users.
It works great for Linux and macOS users. I am sure the version of this helper for Windows requires very little change. Feel free to figure it out and I will update this post.
It works on any OS with git bash though
It is really helpfull
Thanks for this contribution, it works like a charm
No worries, I am glad it helped you out Sushil.
Thanks! Works. As a note, seems to also work without the quotes around the "master" (or branch name)
Nice tip, thanks!