What Was I Thinking?

Follies & Foils of .NET Development
posts - 95 , comments - 352 , trackbacks - 0

(GIT) Remove all local branches except Master

Often I find I retain my local GIT branches long after their usefulness expires.  Deleting them one at a time is a hassle, and probably the reason I don’t clean them up more often.

Fortunately, someone found a better way.  A one line command (ok, its actually 3 commands piped together), and *poof*, all my local branches (EXCEPT master) are deleted.

Use this with caution, as you will lose all work in those branches that haven’t been merged to master yet.

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

You can confirm the branches are gone by listing all your local branches:

$ git branch 
* master

Print | posted on Monday, August 27, 2018 10:59 AM | Filed Under [ GIT DEV ]


No comments posted yet.
Post A Comment

Powered by: