I have a branch called master
and another called dev
. Usually, I do tests and improvements on dev
; when done, I merge it into master
, tag it, and release new version of the application.
Now, I face a decision to make in regard to merging:
- merge
master
intodev
- merge
dev
intomaster
but I am not really sure how the two are different… Any explanation would be welcome.
Best Answer
TL;DR
The main difference lies in where the
master
anddev
branches end up pointing.Full explanation
Merging one branch into another is not a symmetric operation:
dev
intomaster
, andmaster
intodev
,are, in general, not equivalent. Here is an illustrative example that explains the difference between the two. Let's assume your repo looks as follows:
If you merge
dev
intomaster
If
master
is checked out (git checkout master
),and you then merge
dev
(git merge dev
), you will end up in the following situation:The
master
branch now points to the new merge commit (F
), whereasdev
still points to the same commit (E
) as it did before the merge.If you merge
master
intodev
If, on the other hand,
dev
is checked out (git checkout dev
),and you then merge
master
(git merge master
), you will end up in the following situation:The
dev
branch now points to the new merge commit (F'
, whereasmaster
still points to the same commit as it did before the merge (D
).Putting it all together