Resolving merge conflicts
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
<<<<<<< HEADand=======is your current branch. - Between
=======and>>>>>>> featureis 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 --abortReduce 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.