appzasGamesToolsDevLearnCheat sheetsQuick calcsConvertersReferenceNetworkTimeCalculatorsCompareLLM prices

Resolving merge conflicts

Lesson 2 of 410 minIntermediate

Read conflict markers, choose the right result and finish the merge.

A conflict happens when two branches changed the same lines (or one deleted what the other edited) and Git cannot decide. Git stops and asks you.

git merge feature
# CONFLICT (content): Merge conflict in app.py
git status          # lists the files "both modified"

Open the file. Git marked the competing versions:

<<<<<<< HEAD
timeout = 30
=======
timeout = 60
>>>>>>> feature
  • Between <<<<<<< HEAD and ======= is your current branch.
  • Between ======= and >>>>>>> feature is the incoming branch.
  • Edit the file to the result you want, and delete the three marker lines.
git add app.py
git commit            # finishes the merge
# or give up and go back:
git merge --abort

Reduce them

  • Merge main into your branch often, so differences stay small.
  • Keep commits and pull requests small.
  • Agree on a formatter, so reformatting does not touch every line.

CarefulRun the tests after resolving. A file can merge without conflict markers and still be logically wrong. Also check that no <<<<<<< is left in the code: git grep -n "<<<<<<<".

Test yourself

Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.

1. What is between <<<<<<< HEAD and =======?
2. How do you cancel a merge that went wrong?
Hintgit merge with --abort.

Key terms