Skip to content

How to Fix Git Merge Conflict Resolution Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Git Merge Conflict Resolution Error. We cover key concepts, practical examples, and best practices.

You run git merge and get Automatic merge failed; fix conflicts and then commit the result โ€” Git cannot automatically merge changes because the same parts of the same files were modified in both branches.

The Problem

Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

Step-by-Step Fix

Step 1: Identify conflicted files

git status

Expected:

On branch main
You have unmerged paths.
  (fix conflicts and run "git commit")

Unmerged paths:
  both modified:   index.html

Step 2: View the conflict markers

Open the file. You will see:

<<<<<<< HEAD
<h1>Welcome to our site</h1>
=======
<h1>Welcome to our website</h1>
>>>>>>> feature/new-header
  • <<<<<<< HEAD โ€” your current branch's version
  • ======= โ€” separator
  • >>>>>>> feature/new-header โ€” incoming branch's version

Step 3: Resolve the conflict

Edit the file to keep the correct version:

<h1>Welcome to our website</h1>

Remove the conflict markers.

Step 4: Mark as resolved

git add index.html

Step 5: Complete the merge

git commit

Git opens an editor with a default merge message. Save and close.

Step 6: Use a merge tool

# Configure a merge tool
git config merge.tool vimdiff

# Launch merge tool
git mergetool

Step 7: Abort the merge if needed

git merge --abort

This returns to the state before the merge.

Prevention Tips

  • Communicate with your team about which files you are editing
  • Pull and rebase frequently to minimize divergence
  • Use feature branches and merge often
  • Use git diff before merging to see potential conflicts
  • Set up a .gitattributes file for line ending consistency

Common Mistakes with merge conflict

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world GIT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What do the conflict markers mean?

<<<<<<< HEAD starts your version of the conflicting section. ======= separates your version from the incoming version. >>>>>>> branchname marks the end of the incoming version. Everything between HEAD and ===== is what you have locally.

How do I keep all changes from one side?

Use git checkout --ours <file> to keep your version, or git checkout --theirs <file> to keep the incoming version. Then git add <file> and commit.

Can I prevent merge conflicts?

You cannot prevent all conflicts, but you can reduce them: communicate with your team, make smaller more frequent commits, rebase instead of merge for feature branches, and use git diff to preview changes before merging.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro