Delete all local git branches in one command line
August 07, 2020
1 min

When developing you will create lots of local git branches. Let’s see how to delete them all in once with this command line :

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

This will delete all branches except master. If you want to keep other branches (develop, release), you can do it like this :

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

If you want to save everything as an alias to be accessible everywhere in your console add this to your .bashrc file:

alias gbr="git branch | grep -v "master" | xargs git branch -D"

So that when you use gbr it will clean all local branches except master

Related Posts

How to change the remote branch tracked using git
July 20, 2020
1 min
© 2022, All Rights Reserved.

Quick Links

Contact Us

Social Media