Can I delete all the local branches except the current one?

sensorario picture sensorario · Feb 17, 2015 · Viewed 48.3k times · Source

I want to delete all branches that get listed in the output of ...

$ git branch

... but keeping current branch, in one step. Is that possible? If so, how?

Answer

pankijs picture pankijs · Feb 17, 2015
$ git branch | grep -v "master" | xargs git branch -D 

will delete all branches except master (replace master with branch you want to keep, but then it will delete master)