Branches and merges
Resolve a merge conflict
Read conflict markers, choose the correct content, and complete a merge deliberately.
8 minute lesson
A conflict means Git cannot choose a correct result automatically. It is not repository damage. It is a decision Git needs you to make.
Start with:
git status
Git lists the unmerged paths. Open one and look for markers like these:
<<<<<<< HEAD
Search our notes
=======
Find saved notes
>>>>>>> add-search
The first section came from the current branch. The second came from the branch being merged. Read the surrounding code and write the final content you actually want. Do not keep the marker lines.
Then stage the resolved file:
git add README.md
git status
git diff --staged
Staging tells Git that this path is resolved. When every conflict is resolved, complete the merge:
git commit
If you are not ready to resolve the merge, abort it before doing unrelated work:
git merge --abort
This attempts to restore the pre-merge state. Existing uncommitted changes can make restoration harder, which is why a clean working tree matters before merging.
Exercise: create the same line differently on two branches, merge them, resolve the conflict, and inspect the resulting merge commit with git show --stat.
Lesson completed