63
        C---D  =>b1
      /    
     /  E---F  =>b2
     | /   
  A--B =======> master
     | \
     \  G---H  =>b3
      \ 
       I---J   =>b4

I want to merge b1,b2,b3,b4 into master, is it possible merge at once?

something like:

git checkout master
git merge b1 b2 b3 b4
nfpyfzyf
  • 2,891
  • 6
  • 26
  • 30
  • 8
    https://www.kernel.org/pub/software/scm/git/docs/git-merge.html#_merge_strategies See octopus and below. – Alexei Sholik Apr 25 '13 at 06:53
  • 1
    Why you not just try it by yourself. It can work if there is no conflict. – pktangyue Apr 25 '13 at 06:56
  • 4
    @android, since there's already an answer recommending bash usage and another claiming that it simply isn't possible, I think you should rewrite that comment as an answer, because it's actually correct, while the others so far are not. – Kyle Strand Apr 25 '13 at 06:57
  • @KyleStrand Yeah, seeing that no one bothered to research the topic, I've finally decided to do so myself. – Alexei Sholik Apr 26 '13 at 14:30

2 Answers2

67

Git's merge command supports multiple merging strategies. There are two strategies that can merge more than two branches at a time.

See also this question for a less formal description of each one.

octopus

This resolves cases with more than two heads, but refuses to do a complex merge that needs manual resolution. It is primarily meant to be used for bundling topic branch heads together. This is the default merge strategy when pulling or merging more than one branch.

The last statement implies that if you do git merge branch1 branch2 ..., it'll use the octopus strategy.

ours

This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches.

See this question for a use case example.

Community
  • 1
  • 1
Alexei Sholik
  • 7,287
  • 2
  • 31
  • 41
3

Git has a merging strategy called octupus which can merge multiple branches, as long as there are no complex conflicts. The command to do this is exactly as you suggested git merge b1 b2.

jbr
  • 6,198
  • 3
  • 30
  • 42
  • 4
    this is not quite true. the octopus merge strategy can merge an arbitrary number of branches – Nevik Rehnel Apr 25 '13 at 06:55
  • As is said it was the short answer, the octopus strategy only works if there are no complex merges. It will fail if there are any conflicts. And still can't do it in one command, like requested. – jbr Apr 25 '13 at 06:58
  • 6
    Actually, you **can** merge multiple branches in one command. The [Git docs](http://git-scm.com/docs/git-merge) give this as an example: `$git merge fixes enhancements`. –  Apr 25 '13 at 15:17
  • Ah, that's true. I've always thought that merged fixes into enchancements. – jbr Apr 27 '13 at 12:31