How to resolve a Git merge conflict

Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with Git 2.43.0, November 29, 2026.

A merge conflict means both branches changed the same lines and Git needs you to pick. Open the file, find the block between <<<<<<< and >>>>>>>, keep the lines you want, delete the markers, then:

git add <file>
git commit

To back out instead and return to where you were before the merge:

git merge --abort

We reproduced each case below with Git 2.43: a content conflict, a modify/delete conflict, a trial merge with git merge-tree and a commit that slipped through with markers still in the file.

What Git prints

When we merged a branch that changed color = blue to green into a main that had changed it to red, Git printed:

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

The merge is now paused. git status shows which files need you:

On branch main
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   app.conf

For a list of conflicted files and nothing else:

git diff --name-only --diff-filter=U

How to read the conflict markers

Git writes both versions into the file:

line1
<<<<<<< HEAD
color = red
=======
color = green
>>>>>>> feature
line3
  • Between <<<<<<< HEAD and ======= is your current branch (the one you ran git merge on).
  • Between ======= and >>>>>>> feature is the branch you are merging in.
  • Everything outside the block merged cleanly.

It is often hard to choose without seeing what the line was before either change. Set the zdiff3 style and Git adds the original as a third section:

git config --global merge.conflictStyle zdiff3

The same conflict then looked like this, with the common ancestor after |||||||:

<<<<<<< HEAD
color = red
||||||| 6c4aa95
color = blue
=======
color = green
>>>>>>> feature

zdiff3 needs Git 2.35 or later. On older versions use diff3.

Resolve the conflict step by step

  1. Open each conflicted file. Most editors highlight the blocks. VS Code adds “Accept Current Change”, “Accept Incoming Change” and “Accept Both Changes” links above each one.
  2. Edit the block to the final version. Keep one side, both or a mix. Delete all three or four marker lines.
  3. Check no markers are left. After staging, git diff --cached --check printed f:3: leftover conflict marker for each one we missed.
  4. Stage the file with git add <file>. This is how you tell Git the file is resolved.
  5. Commit with git commit. Git fills in a “Merge branch ‘feature’” message.

To work through the files in a merge tool instead, run git mergetool. It opens each conflicted file in turn and stages it when the tool exits successfully. git mergetool --tool-help lists the tools Git can find on your machine (vimdiff was the only one in our test container). By default it leaves a .orig backup of each file. Ours showed up as ?? f.orig, and git clean -n listed it for removal. Set git config --global mergetool.keepBackup false to skip the backups.

If you want one side of a whole file, skip the editing:

git checkout --ours app.conf    # keep your branch's version
git checkout --theirs app.conf  # keep the incoming branch's version
git add app.conf

In our test --theirs replaced the file with the green version and printed Updated 1 path from the index. If you picked the wrong side, git checkout -m app.conf put the conflict markers back.

Other kinds of conflict

What git status or the merge says Meaning Fix
both modified Both sides edited the same lines Edit the markers as above
CONFLICT (modify/delete): f deleted in x and modified in HEAD One side deleted the file, the other changed it Keep it with git add f, or delete it with git rm f
both added Each side created a file with the same name Edit the markers, or keep one side with --ours or --theirs
Binary file conflict (images, archives) Git can’t write markers into binary data git checkout --ours or --theirs, then git add

In the modify/delete case we reproduced, Git left HEAD’s version of the file in place (Version HEAD of f left in tree.) and git status -s showed UD f.

If something goes wrong

  • You want to start over. git merge --abort puts every file back as it was before the merge. In our test the file returned to color = red with a clean status. If there’s no merge in progress it says fatal: There is no merge to abort (MERGE_HEAD missing).
  • git commit refuses. It printed error: Committing is not possible because you have unmerged files. and listed U f. Stage each resolved file with git add first.
  • You committed with markers still in the file. git commit -am did this in our test because -a stages unresolved files too. Fix the file and make a new commit, or git commit --amend if you haven’t pushed.
  • git pull won’t even start. error: Your local changes to the following files would be overwritten by merge is a different problem: you have uncommitted edits. Commit or git stash them, then pull.

Check for conflicts before you merge

Git 2.38 added a trial merge that writes nothing to your working tree:

git merge-tree --write-tree main feature

When the branches conflict it exits with status 1 and prints the conflicted files and CONFLICT (content): Merge conflict in f. A clean result exits 0. This is handy in scripts and CI before an automatic merge.

Conflicts during a rebase or a pull

git pull runs a merge by default, so conflicts from a pull are fixed the same way. If your pull is set to rebase, or you ran git rebase yourself, the steps change slightly (and --ours and --theirs swap meaning). See how to fix a conflict during git rebase. If the merge stops with refusing to merge unrelated histories instead, the branches share no common commit: see that fix.

FAQ

What does a merge conflict mean?

Both branches changed the same lines (or one changed a file the other deleted) since they split, and Git can't tell which version you want. It stops, marks the spot in the file and waits for you to choose. Nothing is lost: both versions are still in the file and in Git's index.

How do I check if there are merge conflicts in Git?

During a merge, git status lists them under "Unmerged paths" and git diff --name-only --diff-filter=U prints just the file names. Before merging, git merge-tree --write-tree main feature (Git 2.38 or later) does a trial merge without touching your files and exits with 1 if it would conflict.

How do I avoid Git merge conflicts?

You can't avoid them entirely, but you can make them smaller: merge or rebase from the main branch often, keep branches short-lived, avoid reformatting whole files in the same branch as real changes and agree on a formatter so whitespace doesn't differ between machines.

How do I fix merge conflicts in GitLab or GitHub?

Both offer a web editor for simple text conflicts on a merge request or pull request. For anything bigger, fetch the branches and resolve locally with the steps on this page, then push. GitHub documents its command-line steps.

Can I commit a file that still has conflict markers?

Yes, by accident. A plain git commit refuses while files are unmerged, but git commit -a stages everything and committed our test file with the markers still in it. Run git diff --cached --check first: it reports each leftover conflict marker.