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.
To delete many branches based on a specified pattern do the following: Open the terminal, or equivalent. Type in git branch | grep "<pattern>" for a preview of the branches that will be deleted. Type in git branch | grep "<pattern>" | xargs git branch -D.
Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.
Not with that syntax. But you can do it like this:
git branch -D 3.2 3.2.1 3.2.2
Basically, git branch will delete multiple branch for you with a single invocation. Unfortunately it doesn't do branch name completion. Although, in bash, you can do:
git branch -D `git branch | grep -E '^3\.2\..*'`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With