On this page
  1. What causes a merge conflict?
  2. How do you read a merge conflict?
  3. How do you avoid merge conflicts?
  4. Where AI coding assistants get this wrong
  5. Checklist
  6. FAQ
    1. What is the difference between a merge conflict and a rebase conflict?
    2. Can I undo a merge conflict?
  7. Related topics
  8. Sources
concept

What Is a Git Merge Conflict?

A merge conflict happens when two branches change the same part of a file. Learn what causes them, how to read the markers, and how to resolve them.

Quick answer

  • A merge conflict occurs when Git can’t automatically reconcile two changes to the same lines of a file.
  • Git marks the conflicting sections with <<<<<<<, =======, and >>>>>>> markers showing both versions.
  • Resolving a conflict means editing the file to the correct merged version and committing the result.

What causes a merge conflict?

A merge conflict happens when two branches modify the same lines of a file differently, or one branch deletes a file another branch modifies. Git can automatically merge changes that touch different lines; conflict occurs when the changes overlap. The most common trigger: two developers (or two AI coding sessions) changing the same function independently, then trying to merge both branches into main. Git doesn’t know which version to keep, so it asks you.

How do you read a merge conflict?

Git inserts conflict markers into the affected file. Everything between <<<<<<< HEAD and ======= is your current branch’s version. Everything between ======= and >>>>>>> other-branch is the incoming branch’s version. Your job: delete the markers, keep the correct code (which may be one side, both sides combined, or something new), and save the file. After resolving all conflicts in a file, git add it and git commit to complete the merge.

<<<<<<< HEAD
const port = 3000;         # your branch's version
=======
const port = process.env.PORT || 3000;  # incoming branch's version
>>>>>>> feature/config-port

# After resolving:
const port = parseInt(process.env.PORT) || 3000;

How do you avoid merge conflicts?

Small, frequent merges: merge main into your branch daily, and keep branches short-lived. Communicate about who is working on what files. Tools like rebase instead of merge can produce a cleaner history but don’t eliminate conflicts — they just ask you to resolve them during the rebase instead of at merge time. The real answer: conflicts are normal and unavoidable at scale. The skill isn’t avoiding them, it’s resolving them quickly without breaking the code.

Where this bites vibecoders

Multi-agent AI coding sessions create merge conflicts at high speed: one session edits the route handler, another edits the same file’s database function, both push, and the vibecoder sees conflict markers for the first time with no idea what they mean. The AI assistants can’t resolve the conflict for you — only you can decide which logic is correct. Learning to read conflict markers is a five-minute skill that pays off every time you work with branches.

Where AI coding assistants get this wrong

  • Running parallel AI coding sessions on the same files with no coordination, producing frequent conflicts.
  • Generating ‘fixes’ that delete conflict markers without resolving them, committing broken syntax.
  • Resolving a conflict by keeping both sides without understanding the logic, combining incompatible changes.
  • Not running tests after resolving a conflict, so a syntactically correct merge produces incorrect behavior.

Checklist

  • Keep branches short-lived and merge main into your branch frequently.
  • Read the conflict markers carefully — understand both sides before choosing.
  • After resolving, run tests to confirm the merge didn’t break behavior.
  • If the conflict is complex, resolve it with the person who wrote the other branch.

FAQ

What is the difference between a merge conflict and a rebase conflict?

They look the same in practice — same conflict markers, same resolution process. The difference is when they happen: merge conflicts occur at merge time (git merge), rebase conflicts occur during rebase (git rebase). Rebase resolves conflicts commit-by-commit, which can be cleaner if you know what you’re doing, but the resolution work is identical.

Can I undo a merge conflict?

Yes: git merge –abort cancels the merge and returns your working directory to its pre-merge state. This is the escape hatch when a merge produces more conflicts than expected and you need to regroup.

Sources

Share: