Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to delete all local branches except master and develop in one command without aliases?

When working on projects with Git Flow or similar workflow where more than one stable branch exists I create a lot of feature branches (feature/do-something-1, hotfix/fix-bug-1, etc.).

Sometimes I need to clear the list of local branches because it is literally impossible to manage them with dozens of rudimentary branches. I usually delete them one at a time by copying and pasting the branch names into the git branch -d command. But it takes so long that it’s easier to delete the entire repository and clone again.

I want to delete all of them except master and develop in one command (without writing additional shell script/aliases), but all solutions I’ve found on the internet only allow you to delete everything except one branch (master, for example). This is not an appropriate solution. Has anyone faced a similar problem?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

 git branch | grep -v " master$" | grep -v " develop$" | xargs git branch -D
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading