Skip to content

How Can I Delete Multiple Branches That Have Been Merged? #22532

Answered by lee-dohm
a-a-ron asked this question in New to GitHub
Discussion options

You must be logged in to vote

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):

git branch --merged master |grep -v -e master| xargs -n 1 git branch -d

I have a Ruby script that I use for this that is a little more flexible a…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants