In this lesson, you will learn exactly what scenarios trigger a merge conflict so you can predict when Git needs your human intervention to finalize a merge.
What is a Merge Conflict?
You have already learned how to merge feature branches into main. Most of the time, Git’s "recursive" merge strategy works perfectly—it looks at the common ancestor of both branches and combines the changes automatically. However, a merge conflict occurs when Git encounters a scenario where it cannot logically decide which version of a file is the "correct" one.
The Trigger Conditions
Git triggers a conflict primarily when the exact same lines in a file have been modified in two different ways.
Imagine two developers, Alice and Bob, are working on a file called README.md.
- The Starting Point: Both branches start with the line:
Version: 1.0. - Alice’s Change: Alice edits her branch to say
Version: 1.1. - Bob’s Change: Simultaneously, Bob edits his branch to say
Version: 1.2.
When you attempt to merge Alice's branch into Bob's, Git looks at that line and panics. It knows that both developers modified the same piece of code, but it has no way of knowing if the final version should be 1.1, 1.2, or something else entirely.
Why Git Pauses
Git stops the merge process to prevent data loss. If Git blindly chose Alice’s version, Bob’s work would disappear; if it chose Bob’s, Alice’s would be lost.
To signal this, Git marks the file as "unmerged" and inserts conflict markers directly into the text:
<<<<<<< HEAD
Version: 1.2
=======
Version: 1.1
>>>>>>> feature-branch
<<<<<<< HEADshows your current branch’s version.=======acts as the divider.>>>>>>> feature-branchshows the incoming version you are trying to merge.
Git effectively says: "I see what you both did, but I don't have the authority to choose the winner. Please inspect these lines, edit the file to your desired final state, and finalize the commit."
Key Takeaway: A merge conflict is not an error; it is a safety mechanism Git uses to pause the merge whenever two branches contain competing changes on the exact same lines of code.