Delete merged branches
Sometimes you have a huge list of merged branches.
git checkout master
git branch -d $(git branch --merged | sed '/* /d' | sed 's/^..//' | paste -sd " ")
What does it do?
type git branch --merged
sed '* /d'
will remove the branch your on
sed 's/^..//'
will remove the two spaces in front of each branch
paste -sd " "
will put all the lines onto one line separated by a single space.
git branch -d
delete the branches.
Note
git branch --merged
will actually list any branches which points to a commit within your current branch. If you type git branch foo
the foo branch will actually reference a commit within your current branch so git will mark it as "merged".
Written by Kristian Lewis Jones
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
khasinski
591.1K
dmichaelavila
500.4K
Related Tags
#git
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#