Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I merge multiple branches into master?

Tags:

git

        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 
like image 654
nfpyfzyf Avatar asked Apr 25 '13 06:04

nfpyfzyf


People also ask

How do I merge all branches?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.

Can you merge a branch into master multiple times?

Merging a branch multiple times into another works fine if there were changes to merge. Show activity on this post. Actually yes you totally can, when you merge again it will bring over any commits that don't exist on production.

How do I merge branches to master in GitHub?

In GitHub Desktop, click Current Branch. Click Choose a branch to merge into BRANCH. Click the branch you want to merge into the current branch, then click Merge BRANCH into BRANCH. Note: If there are merge conflicts, GitHub Desktop will warn you above the Merge BRANCH into BRANCH button.


1 Answers

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.

like image 58
Alexei Sholik Avatar answered Sep 17 '22 22:09

Alexei Sholik