Error Encyclopedia
CONFLICT

Git Merge Conflict

Learn how to resolve git merge conflicts. Understand conflict markers, use merge tools, and prevent conflicts in collaborative development.

What Does This Error Mean?

A git merge conflict occurs when Git cannot automatically resolve differences in code between two branches being merged. This happens when the same part of the same file was modified differently in both branches, and Git needs human guidance to decide which version to keep.

Common Causes

1

Two developers edited the same lines in the same file on different branches

2

One developer deleted a file while another modified it

3

Changes to the same function signature or interface on parallel branches

4

Rebase operations encountering commits that conflict with the base branch

5

Cherry-pick conflicts when applying patches to branches with overlapping changes

6

Stash apply or pop conflicts when the working directory has changes

How to Fix It

Identify conflicting files

Use git status to list all files with merge conflicts.

# See which files have conflicts
git status

# List conflicted files specifically
git diff --name-only --diff-filter=U

# Show conflict summary
git log --merge

Resolve conflicts manually

Open conflicted files and edit them to keep the desired changes, removing conflict markers.

<<<<<<< HEAD
// Your current branch changes
const price = 100
=======
// Incoming branch changes
const price = 200
>>>>>>> feature-branch

// ✅ Resolved: keep the correct version
const price = 150

Use a merge tool

Launch a visual merge tool to resolve conflicts side by side.

# Configure a merge tool
git config merge.tool vscode
git config mergetool.vscode.cmd "code --wait $MERGED"

# Launch merge tool
git mergetool

# Common merge tools: vscode, meld, kdiff3, beyondcompare

Abort the merge

If conflicts are too complex, abort the merge and start fresh.

# Abort the current merge
git merge --abort

# If rebase conflicts
git rebase --abort

# Reset to previous state
git reset --hard HEAD

Before & After Examples

❌ Before
<<<<<<< HEAD
function calculateTotal(items) {
  return items.length * 10
}
=======
function calculateTotal(items, tax) {
  return items.reduce((sum, i) => sum + i.price, 0) * (1 + tax)
}
>>>>>>> feature-tax
✅ After
function calculateTotal(items, tax = 0) {
  return items.reduce((sum, i) => sum + i.price, 0) * (1 + tax)
}

Related Tools

Use these tools to debug and fix this error:

Related Errors

Other common errors in this category:

Frequently Asked Questions

Can I prevent merge conflicts?

Not entirely, but you can reduce them by: communicating with your team about who is working on what, rebasing frequently to keep branches up to date, using smaller more focused branches, and avoiding long-lived feature branches.

What do the conflict markers mean?

<<<<<<< HEAD marks the start of your current branch's changes. ======= separates your changes from the incoming changes. >>>>>>> branch-name marks the end of the incoming changes. Everything between <<<<<<< and ======= is your version; between ======= and >>>>>>> is their version.

Should I use merge or rebase?

Merge preserves history (creates merge commits) and is safer for public branches. Rebase creates linear history by replaying commits and is better for feature branches before merging to main.