Live on Product Hunt Intraface launched today. Less steering, more vacations. See the launch
Start for free

What is a merge conflict?

A merge conflict happens when two changes to the same file touch the same lines in different ways and a tool cannot combine them automatically. Git stops, marks the disputed region with conflict markers, and waits for a person to pick one side, or write a mix of both, before the merge can finish.

Part of Glossary: the terms behind MCP, coding agents and shared pages, defined plainly.

How it works

Both edits start from version 3 and change the same line; the first lands, the second collides and a person has to decide.version 3the shared startAna's copyline 12: an emailBen's copyline 12: a linksame line, two answersmergeline 12 changed twice1. both pull1. both pull2. lands first3. conflict4. markers, Ben decides
  1. Two people start from the same version of a file and each change it. Changes to different lines merge on their own.

  2. When both changed the same lines, the merge has no rule for which to keep. Git prints CONFLICT (content) and pauses before committing.

  3. The file gets markers: your side above =======, theirs below. In diff3 style the original lines appear too, after |||||||.

  4. You edit the region into what it should say, delete the markers, mark the file resolved with git add, and finish the merge.

  5. Some systems refuse earlier: the second write to a changed file is rejected and you are asked to update first, so markers never reach the file.

Source: Pro Git: Basic Branching and Merging

Merge conflict versus a clean merge

Most merges are clean. You changed the header, your colleague changed the footer, and the tool takes both because it can see that each region was touched by only one side. A conflict is the case the tool refuses to guess: both of you changed the same region, and the two results differ. The git merge documentation puts it plainly: when both sides changed the same area, git "cannot randomly pick one side over the other" and asks you to resolve it.

So a conflict is not a failure of the tool. It is the tool declining to make an editorial decision on your behalf.

Why it matters

Conflicts are the visible cost of letting people work in parallel on one file. The alternative, locking the file while one person edits, avoids conflicts by making everyone else wait. Most teams accept the occasional conflict instead, because a conflict only appears where two people genuinely disagreed about the same lines, and that is a conversation worth having anyway.

The frequency is what you can control. Small, frequent publishes shrink the window in which someone else can change the same lines. Pulling before you start, and again before you publish, catches most overlaps while they are still trivial.

Common mistakes

  • Deleting one side without reading it. The other side changed those lines for a reason. Read both, then decide.
  • Leaving markers in the file. A <<<<<<< line in HTML renders as text; in code it is a syntax error. Search for the markers before you commit.
  • Fixing the symptom, not the overlap. If the same two people keep conflicting on one file, split the file or agree who owns which part.
  • Panicking mid-merge. Nothing is lost. git merge --abort or git rebase --abort returns you to where you started.

FAQ

Why do I get a merge conflict when I only changed one line?
Because the other side changed that line too, or one right next to it. Merge tools work on regions of adjacent lines, so two small edits a line apart can land in the same region. Some systems also conflict per file rather than per line, so any overlap in the same file counts.
Can a merge conflict be resolved automatically?
Only by choosing a rule in advance, such as git's ours strategy, which always keeps your side. That is a decision, not a merge. Tools that never conflict, such as CRDTs, do so by defining a result for every overlap, which is not always the result you wanted.
Does a merge conflict lose any work?
No. Both versions of the disputed lines are in the file between the markers, and git still has both commits. If you want out, git merge --abort or git rebase --abort restores the state before you started.

Stop sending HTMLover Slack.

Create an account in a minute, connect your coding agent, and make your first board.