What is a "Merge Conflict," and how does Git determine that a conflict has occurred?
Last updated
A merge conflict occurs when Git cannot automatically reconcile changes from two branches because they modified the same region of a file in incompatible ways. Git detects this during its three-way merge by comparing each side against the common ancestor line by line (hunk by hunk).
How Git decides:
For each changed region it compares the merge base to
oursandtheirs.If only one side changed a region, that change is taken automatically.
If both sides changed the same region differently, Git can't choose and marks a conflict.
What you see: Conflict markers
<<<<<<<,=======,>>>>>>>wrap the competing versions in the file.Beyond simple text overlaps:
Conflicts also arise from add/add, delete/modify, or rename collisions, not just overlapping edits.
Git is line-based, so it won't flag semantic conflicts (code that merges cleanly but breaks logically).
- https://git-scm.com/docs/merge-strategies/2.49.0
- https://dev.to/shrsv/git-internals-how-git-merge-really-works-2dn5
- https://dev.to/imevanc/managing-merge-conflicts-in-git-strategies-and-best-practices-21g2
- https://codeinput.com/blog/git-conflict-revisions
- https://blog.git-init.com/the-magic-of-3-way-merge/
- https://www.kodeco.com/books/advanced-git/v1.0/chapters/2-merge-conflicts
- https://www.atlassian.com/git/tutorials/using-branches/git-merge