What exactly is a merge conflict?
Solution 1:
You will have a conflict if you merge:
-
branch2
tomaster
(no conflict) -
branch3
tomaster
(conflict):
That is because:
- The common ancestor would be
master
(with a second line empty) - the source content is
branch3
(with a second line including "3") - the destination content is on latest of
master
(with a second line including "2", from the merge ofbranch2
tomaster
)
Git will ask you to choose which content to keep ("3", "2", or both).
First, do the merges after:
git config merge.conflictstyle diff3
See "Fix merge conflicts in Git?".
Solution 2:
A merge conflict happens when two branches both modify the same region of a file and are subsequently merged. Git can't know which of the changes to keep, and thus needs human intervention to resolve the conflict.
In this case, your steps 2 and 3 create two branches that have conflicting changes.