In the past month I’ve done a lot of traveling. Traveling means noodling – lots of topic branches laying around from airplane rides and hotel hacking. Today I decided to get rid of the topic branches which had been merged into master. But how?
When in doubt, ask Scott Chacon. Here’s how to delete all the branches which are a subset of master (and therefor contain nothing juicy):
git branch --contains master | grep -v master | xargs git branch -d



That’s actually not going to work.
git branch --contains mastergives you all branches that are a descendent of master, whereas you want all branches that are an ancestor of master. You should be usinggit checkout master && git branch --mergedAs I recall, git-branch -d will remove anything safe and ignore others, so it’d still work. But thanks for the tips, both of you. It never even occurred to me
git-branchcould have such parameters.kballard is right, I misunderstood your question, which was asking for ‘subsets of a given branch’ – “git branch
-contains master” will give you every branch that has the sha in it’s history that ‘master’ resolves to. If master has moved forward since the branching, it won’t work how you’re describing it here. To find the branches that have already been merged in, ‘-merged’ is in fact what you want. Apologies for the confusion.When in doubt, ask Scott Chacon, then make damn sure he understood what you were asking, and was not drinking heavily at the time :)
What version of git has the—merged option on branch? I’ve got 1.5.5.3 and it’s not there.
really? taking a quick look at the docs, it looks like—merged was added on Apr 17:
and 1.5.5.3 was tagged on May 27:
So it certainly should have been there. Perhaps you mean ‘1.5.5-rc3’? That was released a week before the ‘—merged’ option was added.
Scott
I think
git branch --mergedis scheduled for 1.5.6.