Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is merging branch A into B same as merging B into A?

Tags:

In a git repository, is merging branch A into B same as merging B into A?

like image 811
user2436428 Avatar asked Aug 28 '13 10:08

user2436428


People also ask

Can you merge one branch into another?

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.

What happens when we merge two branches?

When you perform a merge, you effectively merge one branch into another—typically a feature branch or bug fix branch into a main branch such as master or develop. Not only will the code changes get merged in, but also all the commits that went into the feature branch.

Does git merge change both branches?

No, merging does only affect one branch.

Does it matter which branch you merge from?

Usually it does not matter if both branches are topic or feature branches. However, if you have an integration branch or a branch that marks what's been published, you definitely want to use the long lived integration branch as the one that's checked out and merge the other one into it.


1 Answers

No, if you merge A into B, then in the end branch A will only have A's changes, and B will have both A+B changes.

If you merge B into A, then A with have both A+B changes, and B will only have B's changes.

Start:

 /A1-A2-A3 X   \B1-B2-B3 

A to B with a merge commit:

 /A1-A2-A3 X   \B1-B2-B3-A*(1,2,3) 

A to B with fast forward:

 /A1-A2-A3 X   \A1-A2-A3-B1'-B2'-B3' 

B to A with merge commit:

 /A1-A2-A3-B*(B1,B2,B3) X   \B1-B2-B3 

B to A with fast forward:

 /B1-B2-B3-A1'-A2'-A3' X   \B1-B2-B3 
like image 114
Douglas Leeder Avatar answered Oct 02 '22 10:10

Douglas Leeder