Video in progress
How does a three-way merge work, and why does the merge base matter?
Git compares the tips of two branches with their closest common parent commit (the merge base). A place changed on only one side is taken automatically, and if both sides changed the same place differently, it is a conflict.
📖 Answer
git merge-base main feature/discounts
This command shows which commit Git takes as the "base". Then the logic for each piece is simple:
| base | main | feature | result |
|---|---|---|---|
| X | X | Y | Y |
| X | Z | X | Z |
| X | Z | Z | Z |
| X | Z | Y | conflict |
That is why if the merge base is wrong, the result comes out strange too. For example, if you rebase a branch and also merge the old one, Git sees the same changes as "two different ones".
In criss-cross merges (two branches merged into each other several times) there are several merge bases. The default ort strategy (which replaced recursive in Git 2.34+) first combines them into a virtual base and merges after that.
To make conflicts easier to read:
git config --global merge.conflictStyle zdiff3
Then the base version also shows between the conflict markers, which makes it much easier to understand what each side changed.
Sign up to mark studied questions and save your progress.