A merge conflict happens when two branches modify the same lines in a file. Git can't automatically combine them and needs your decision on which version to keep.

Introduction

This article covers troubleshooting steps and solutions for Git Merge Conflict: Complete Resolution Guide. The error typically occurs in production environments and can cause service disruptions if not addressed promptly.

Symptoms

When merging, you see:

bash
Auto-merging src/app.js
CONFLICT (content): Merge conflict in src/app.js
Automatic merge failed; fix conflicts and then commit the result.

Checking status shows:

bash
Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/app.js

Common Causes

Git merges automatically when changes don't overlap. But when both branches edit the same lines, Git pauses and marks the conflict for you to resolve.

Common scenarios: - Two developers edit the same function - One branch adds code where another removes it - Both branches modify configuration values - Concurrent changes to shared utilities

Step-by-Step Fix

Check which files have conflicts: ``bash git status

List only conflicted files: ``bash git diff --name-only --diff-filter=U

See conflict summary: ``bash git diff --check

This shows remaining conflict markers.

Understanding Conflict Markers

Open a conflicted file:

bash
cat src/app.js

You'll see:

bash
<<<<<<< HEAD
const maxValue = 100;
const minValue = 0;
=======
const maxValue = 50;
>>>>>>> feature-branch

The structure: - <<<<<<< HEAD - Your current branch's version starts - ======= - Separator between versions - >>>>>>> feature-branch - The branch you're merging's version ends

Solution 1: Manual Resolution

Edit the file directly, removing markers and choosing content:

bash
nano src/app.js

Keep one version: ``javascript const maxValue = 100; const minValue = 0;

Or combine both: ``javascript const maxValue = 100; const minValue = 0; // Alternative: const maxValue = 50;

Remove all conflict markers (<<<<<<<, =======, >>>>>>>).

Stage the resolved file: ``bash git add src/app.js

Solution 2: Keep One Side Entirely

For a file where you want your version:

bash
git checkout --ours src/app.js
git add src/app.js

For the incoming branch's version:

bash
git checkout --theirs src/app.js
git add src/app.js

Note: During a merge, --ours is HEAD (your branch), --theirs is the branch being merged.

Solution 3: Use Git Merge Tools

Git provides built-in merge tools:

bash
git mergetool

Configure your preferred tool:

bash
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'

For VS Code, it opens a three-way merge view showing: - Current (yours) - Incoming (theirs) - Result (merged)

Solution 4: Abort the Merge

If conflicts are overwhelming, abort:

bash
git merge --abort

This returns to the state before the merge attempt.

Solution 5: Resolve Multiple Conflicts

For many conflicted files, work systematically:

```bash # See all conflicts git diff --name-only --diff-filter=U

# Resolve each file for file in $(git diff --name-only --diff-filter=U); do echo "Resolving $file" # Edit each file done

# Check for remaining markers git diff --check ```

Solution 6: Binary File Conflicts

Binary files can't be merged textually:

bash
CONFLICT (content): Merge conflict in assets/logo.png

Choose which version to keep:

```bash # Keep your version git checkout --ours assets/logo.png git add assets/logo.png

# Keep their version git checkout --theirs assets/logo.png git add assets/logo.png ```

Solution 7: Accept All Changes from One Side

For a clean resolution preferring one branch:

```bash # Accept all incoming changes git checkout --theirs . git add .

# Or accept all your changes git checkout --ours . git add . ```

Use carefully - this affects all conflicted files.

Solution 8: Use git merge with Strategy Options

Apply automatic resolution strategies:

```bash # Prefer your changes for all conflicts git merge -X ours feature-branch

# Prefer their changes for all conflicts git merge -X theirs feature-branch ```

This still merges non-conflicting changes normally, but auto-resolves conflicts by choosing one side.

Solution 9: Three-Way Merge with Base

See the common ancestor to understand both changes:

bash
git show :1:src/app.js  # Base version (common ancestor)
git show :2:src/app.js  # Your version (HEAD)
git show :3:src/app.js  # Their version (merged branch)

This helps understand how each branch diverged.

Verification

Confirm all conflicts resolved: ``bash git diff --check

No output means no conflict markers remain.

Check status: ``bash git status

Should show no "Unmerged paths".

Complete the merge: ``bash git commit

Git creates a merge commit with a default message. Edit if needed:

bash
git commit -m "Merge feature-branch: resolve configuration conflicts"

Verify the result: ``bash git log --oneline --graph -5

Shows the merge commit connecting both branches.

Prevention Strategies

Pull frequently: ``bash git pull --rebase origin main

Keeps your branch close to main, reducing merge conflicts.

Communicate with team: Coordinate on which files each person works on to avoid overlap.

Use smaller commits: Frequent, focused commits are easier to merge than large changes.

Review before merging: ``bash git diff main...feature-branch

Anticipate conflicts before they happen.

Common Patterns

Same function, different implementations: Combine the best parts of both:

javascript
// Your version had validation
function process(value) {
  if (!isValid(value)) return null;
  // Their version had optimization
  return optimizedTransform(value);
}

Configuration conflicts: Merge configurations intelligently:

json
{
  "featureA": true,   // Your addition
  "featureB": false,  // Their addition
  "timeout": 5000     // Both had this, kept higher value
}

Import statement conflicts: Combine imports from both branches:

javascript
import { ComponentA } from './a';  // Your import
import { ComponentB } from './b';  // Their import
  • [Technical troubleshooting: Fix Git Bisect Skip Marking Bad Commit Incorrectly](bisect-skip-marking-bad-incorrectly-git)
  • [Technical troubleshooting: Fix Cherry Pick Range Wrong Order Git Issue in Git](cherry-pick-range-wrong-order-git)
  • [Fix Credential Helper Not Storing Wsl2 Git Issue in Git](credential-helper-not-storing-wsl2-git)
  • [Fix Git Filter-Branch Rewrite Breaking GPG Commit Signatures](filter-branch-rewrite-breaking-signatures-git)
  • [Git Abort Rebase and Recover: Complete Guide](fix-git-abort-rebase)

<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "TechArticle", "headline": "Git Merge Conflict: Complete Resolution Guide", "description": "Learn how to resolve git merge conflicts with manual editing, merge tools, and proper conflict markers. Complete guide for beginners.", "url": "https://www.fixwikihub.com/fix-git-merge-conflict-resolution", "publisher": { "@type": "Organization", "name": "FixWikiHub", "url": "https://www.fixwikihub.com" }, "author": { "@type": "Person", "name": "FixWikiHub Editorial Team" }, "datePublished": "2025-11-13T20:34:55.825Z", "dateModified": "2025-11-13T20:34:55.825Z" } </script>