git: Delete All Branches but Master
Maintenance is incredibly important in any project, but if you want to take your professionalism to the next level, you should keep your git environment in shape. Unfortunately I'm not that guy -- I leave git branches laying around, even after they've been merged into master
. GitHub even provides a button to do the cleanup but I can't be bothered. Not good.
When you're ready to do some real cleanup on a repository, throw this at it:
git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/^/git branch -d /' | bash
The shell command above deletes every branch in your local checkout except for master
branch. This is a dangerous script but you could always check out a given branch from a remote like GitHub if you happen to need it!
![Welcome to My New Office]()
My first professional web development was at a small print shop where I sat in a windowless cubical all day. I suffered that boxed in environment for almost five years before I was able to find a remote job where I worked from home. The first...
![5 HTML5 APIs You Didn’t Know Existed]()
When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It." Can you blame us though? We watched the fundamental APIs stagnate for so long that a basic feature...
![Create Spinning, Fading Icons with CSS3 and MooTools]()
A goal of my latest blog redesign was to practice what I preached a bit more; add a bit more subtle flair. One of the ways I accomplished that was by using CSS3 animations to change the display of my profile icons (RSS, GitHub, etc.) I...
![Image Reflection with jQuery and MooTools]()
One subtle detail that can make a big difference on any web design is the use of image reflections. Using them too often can become obnoxious but using reflections on large, "masthead" images is a classy enhancement. Unfortunately creating image reflections within your...
The script becomes less dangerous, when it uses the
variant instead of the upper case
-D
. Then branches are only deleted, when they are already merged in any of the remaining branches, and no work is lost. (Also, the error messages show you, which branches have work, that has not yet landed in master.)Updated my post! Thank you!
git remote prune origin -)
Thank you, this worked well for me. I first tried it with
-d
, which deleted some, and then decided to go for-D
, which did end up deleting everything butmaster
.