recent posts

Clean up local git branches

Here is a quick way to remove a bunch of local branches without deleting "develop" or "master". The only caveat is it doesn't delete anything similar to "develop" or "master", so if you named a branch "banana_develop", it won't delete that branch.

git branch | grep -v "develop" | grep -v "master" | xargs git branch -D

grep -v means an inverted match - get all the branches and ignore "develop" and "master" branches.

xargs git branch -D will do the dirty work of deleting all LOCAL branches. This will not affect remote branches.


You may want to run the snippet below first to verify you know what is being deleted.
git branch | grep -v "develop" | grep -v "master"


Clean up local git branches Clean up local git branches Reviewed by JJ The Engineer on 10:39 AM Rating: 5

No comments:

Powered by Blogger.