← Git from Scratch Lesson 12 of 17 · 10 XP

Merge conflicts

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

If two branches changed the same lines of the same file, git doesn't know which version is right. This is a conflict:

git merge feature
# CONFLICT (content): Merge conflict in readme.md
# Automatic merge failed; fix conflicts and then commit the result.

Git puts both versions into the file, with markers:

<<<<<<< main
the text from your current branch
=======
the text from the branch being merged
>>>>>>> feature

How to resolve it:

  1. open the file (cat readme.md) and decide what text should remain: one version, the other, or a combination;
  2. rewrite the file so that no markers are left;
  3. git add readme.md — mark the conflict as resolved;
  4. git commit -m "…" — finish the merge.

A conflict isn't an error or a reason to panic; it's a normal part of teamwork. To have fewer of them, keep branches small and merge main into yours often.

Changed your mind about merging? On your own computer, git merge --abort returns everything to how it was before the merge.

Task. The second line of readme.md was changed differently in main and in feature. Merge feature into main, resolve the conflict so that the file consists of two lines — # My project and Version 2 — and finish the merge with the commit merge feature.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.