What Was I Thinking?

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

My Links


Article Categories


Post Categories

Check These Out


Monday, August 27, 2018

(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

Posted On Monday, August 27, 2018 10:59 AM | Comments (0) | Filed Under [ GIT DEV ]

Powered by: