Fastest way to delete all merged branches in master (or any other branch)
git branch --merged | grep -v "*" | grep -v master | xargs -n 1 git branch -d
Written by Luciano Sousa
Related protips
2 Responses
This assumes you have all branches checked out. "git branch -r --merged" will give you all remote branches that are merged in to whatever your current branch is. Also, depending on your branching strategy and how you deal with bugs or hotfixes, you may want to filter on how long it's been since the branch was touched.
Why the "grep -v dev"?
over 1 year ago
·
Thanks for the answer @adevore3.
So, I just removed the grep -v dev. There is no nonse at all. Sorry about that.
About the previously question.
I always run this command on master branch.
About the bugs and hotfixes branches, I just merge it when it's fully tested.
I mean, I run this command always to remove branches I forgot to.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
khasinski
591.1K
dmichaelavila
500.4K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#