Menu
Coddy logo textTech

Merge Conflicts

Part of the Version Control section of Coddy's Terminal journey — lesson 37 of 58.

If both branches changed the same lines of the same file, Git cannot guess which version to keep. It pauses the merge and asks you to decide.

The conflicted file gets special markers showing both versions:

<<<<<<< HEAD
the version on main
=======
the version on feature
>>>>>>> feature

Your job is to edit the file by hand: pick one version, combine them, or write something new. Then remove all the conflict markers (the <<<, ===, >>> lines).

Once the file looks correct, stage it and finalize the merge with another commit:

git add notes.txt
git commit -m "Resolve merge conflict in notes"

If you change your mind partway through, you can abort the whole thing and go back to the pre-merge state:

git merge --abort
challenge icon

Challenge

Medium

The folder contains notes.txt with the line hello.

Initialize the repo and commit the initial file. Branch off into alt, change notes.txt to say hi from alt, and commit.

Switch back to main, change notes.txt to say hi from main, and commit.

Try to merge alt into main. The merge will conflict. Abort it with git merge --abort, then print the contents of notes.txt with cat to confirm the file is back to the main version.

Cheat sheet

When both branches edit the same lines, Git pauses the merge and adds conflict markers to the file:

<<<<<<< HEAD
the version on main
=======
the version on feature
>>>>>>> feature

Edit the file to the desired result, remove all markers, then stage and commit:

git add notes.txt
git commit -m "Resolve merge conflict in notes"

To cancel the merge and restore the pre-merge state:

git merge --abort

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Version Control