7

Remove all git branches except master

 3 years ago
source link: https://pawelgrzybek.com/remove-all-git-branches-except-master/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Remove all git branches except master

Published: 2020.12.20 | 1 minutes read

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 👋

If you liked this article, please share it on Twitter.

Copyright © 2020 Pawel Grzybek

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK