~/hackweb.dev
Resolving Merge Conflicts
Quiz
...

Resolving Merge Conflicts

intermediate · updated Tue Sep 08 2026Contribute

Handle conflicts when Git can't automatically merge changes.

Resolving Merge Conflicts

Conflicts happen when Git can’t automatically combine changes from two branches. You must resolve them manually.

When Conflicts Occur

  • Two branches modify the same line in a file
  • One branch deletes a file the other modifies
  • Both branches add a file with the same name

Conflict Markers

<<<<<<< HEAD
your changes on the current branch
=======
changes from the incoming branch
>>>>>>> feature
  • <<<<<<< HEAD — your current changes
  • ======= — divider
  • >>>>>>> feature — incoming changes

How to Resolve

  1. Open the conflicted file
  2. Choose which changes to keep (or combine both)
  3. Delete the conflict markers
  4. Save the file
git add resolved-file.js
git commit -m "Resolve merge conflict in resolved-file.js"

Using a Merge Tool

git mergetool

Opens a visual diff tool to help resolve conflicts side by side.

Aborting a Merge

git merge --abort

Returns to the state before the merge started.

Best Practices

  • Resolve conflicts soon after they appear
  • Communicate with your team about conflicting changes
  • Test your code after resolving conflicts
  • Use git diff to review changes before committing

Common Mistakes

  • Accidentally deleting code from the other branch
  • Forgetting to remove conflict markers
  • Committing without git add first
  • Not testing after resolution