How Can I Delete Multiple Branches That Have Been Merged? #22532
-
Is there an easy way to delete all merged branches instead of deleting them one by one using |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Warning** :** While the recommendations here aren’t inherently destructive (since they are only deleting merged branches), recovering branches you didn’t mean to delete can be complicated and time-consuming. Use these techniques at your own risk! Depending on the branching strategy in your repository, this can be fairly simple or somewhat complicated. If you want to delete all branches that have been merged into
I have a Ruby script that I use for this that is a little more flexible and has some nice options. It was based off of a Gist I found for the same thing. I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the great information. This helps a lot! |
Beta Was this translation helpful? Give feedback.
-
I just realized that I haven’t been deleting my branches as I go when merging PRs. This has been an oversight for a long while, so I now have a huge set of branches that I’d like to delete. Is it possible to bulk delete branches? Or do I have to delete them all one by one? |
Beta Was this translation helpful? Give feedback.
-
Hey @happydogcode, this is a great question and one that was asked in a previous topic. You can find a solution here. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much! I will look there. |
Beta Was this translation helpful? Give feedback.
-
I’m presuming this only applies to local branches? |
Beta Was this translation helpful? Give feedback.
Warning** :** While the recommendations here aren’t inherently destructive (since they are only deleting merged branches), recovering branches you didn’t mean to delete can be complicated and time-consuming. Use these techniques at your own risk!
Depending on the branching strategy in your repository, this can be fairly simple or somewhat complicated. If you want to delete all branches that have been merged into
master
then you can use this one-liner on macOS or Linux (it should also work on Windows in one of the various Unix shell extensions):I have a Ruby script that I use for this that is a little more flexible a…