How to Resolve Git Merge Conflicts
Advertisement
Ad
What is a Merge Conflict?
A conflict happens when Git can't automatically merge changes because two branches edited the same lines. You must resolve it manually.
What a Conflict Looks Like
<<<<<<< HEAD
const color = "blue";
=======
const color = "red";
>>>>>>> feature
Step-by-Step Resolution
- Run
git statusto see conflicted files. - Open each file and find the
<<<markers. - Edit to keep the correct code, removing the markers.
- Stage and commit:
git add conflicted-file.js
git commit -m "Resolve merge conflict"
Resolved Version
const color = "blue"; // chose this, removed all markers
Helpful Commands
git merge --abort # cancel the merge
git diff # see conflicts
# Use VS Code's built-in merge editor for ease
Avoiding Conflicts
- Pull frequently to stay up to date.
- Keep branches short-lived.
- Communicate who's editing what.
FAQs
Can I undo a bad resolution?
Yes — git merge --abort before committing, or revert the commit after. More in our how-to guides.
Which tool helps most?
VS Code's visual merge editor makes conflicts much easier.
