I'd like to clean up my local repository, which has a ton of old branches: for example 3.2
, 3.2.1
, 3.2.2
, etc.
I was hoping for a sneaky way to remove a lot of them at once. Since they mostly follow a dot release convention, I thought maybe there was a shortcut to say:
git branch -D 3.2.*
and kill all 3.2.x
branches.
I tried that command and it, of course, didn't work.
git branch -D $(git branch | grep 3.2*)
- this worked for me. It deletes the branches whose name starts with "3.2".grep
- pattern matching in the output (ofgit branch
in this case).$()
- means execute and place the result.|
- chaining.-D
is a force delete, should use-d
in most cases to be safer first.git branch | grep "<pattern>" | xargs git branch -D
much easier