Skip to content

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:

  1. git branch β€” list all branches
  2. grep -v "master" β€” remove master from the list
  3. xargs git branch -D β€” execute git branch -D against remaining branches

So helpful, isn’t it? Catch you next time πŸ‘‹

comments powered by Disqus