I follow a development process where I create a new local branch for every new feature or story card. When finished I merge the branch into master and then push.
What tends to happen over time due to a combination of laziness or forgetfulness, is that I end up with a large list of local branches, some of which (such as spikes) may not have been merged.
I know how to list all my local branches and I know how to remove a single branch but I was wondering if there was a Git command that allows me to delete all my local branches?
Below is the output of the git branch --merged command.
cd ~/projects/application git branch --merged Output:
STORY-123-Short-Description STORY-456-Another-Description STORY-789-Blah-Blah * master All attempts to delete branches listed with grep -v \* (as per the answers below) result in errors:
error: branch 'STORY-123-Short-Description' not found. error: branch 'STORY-456-Another-Description' not found. error: branch 'STORY-789-Blah-Blah' not found. I'm using:
- Git 1.7.4.1
- Ubuntu 10.04 (Lucid Lynx)
- GNU Bash, version 4.1.5(1)-release
- GNU grep 2.5.4

rm -rf /my_cool_repoand reclone the repo. If I do not have an active branch that is the easiest way to "clean out all local branches" IMO. Clearly not the answer if you are actively doing work on a branch.git branch | xargs git branch -Dthis command works for me