Resolving Merge Conflicts
A merge conflict happens when Git cannot automatically combine changes because the same lines were edited differently on both branches. Git pauses the merge and marks the conflicting sections for you to resolve manually.
Resolving conflicts means editing the file to keep the correct content, removing Git's conflict markers, then staging and committing the resolved file to complete the merge.
<<<<<<< HEAD
your changes
=======
their changes
>>>>>>> branch-nameRecognizing a conflict
Git marks conflicts with `<<<<<<<`, `=======`, and `>>>>>>>` inside the file, showing both versions of the conflicting lines side by side.
Resolving and completing the merge
Edit the file to keep the correct content and delete the conflict markers, then run `git add filename` and `git commit` to finish the merge.
git merge feature-loginCONFLICT (content): Merge conflict in app.js
Automatic merge failed; fix conflicts and then commit the result.Git reports a conflict in app.js and pauses the merge for manual resolution.
git add app.js
git commit -m "Merge feature-login, resolve conflicts"[main 6e2a1bc] Merge feature-login, resolve conflictsAfter manually fixing the file, staging and committing completes the merge.
Key points
- Merge conflicts occur when the same lines change differently on two branches.
- Git marks conflicts with <<<<<<<, =======, and >>>>>>>.
- You must manually edit the file to resolve the conflict.
- Stage and commit the resolved file to complete the merge.
