Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to How To Guides
How to Resolve Git Merge Conflicts

How to Resolve Git Merge Conflicts

How To Guides2,833 viewsBy Admin
how-toresolvemergeconflicts

Advertisement

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

  1. Run git status to see conflicted files.
  2. Open each file and find the <<< markers.
  3. Edit to keep the correct code, removing the markers.
  4. 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.

Advertisement