Git Merge Conflict: How to Resolve (Tested)
A git merge conflict happens when two branches change the same lines and git can't pick a winner automatically. git marks the spot in the file with <<<<<<<, =======, and >>>>>>>. We reproduced one from scratch and recorded exactly what git prints and writes.
1. How we reproduced it
We made one file, committed it, then branched twice and edited the same line differently on each branch before merging both into master.
git init
git config user.email "test@example.com"
git config user.name "Test User"
echo "line one" > file.txt
git add file.txt
git commit -m "initial commit"
git checkout -b branch-a
echo "line one from A" > file.txt
git commit -am "A edits line"
git checkout master
git checkout -b branch-b
echo "line one from B" > file.txt
git commit -am "B edits line"
git checkout master
git merge branch-a # fast-forward, no conflict
git merge branch-b # conflicts with branch-a's change
The second merge printed:
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
git merge exited with status 1.
2. The exact conflict markers git writes
Here is the full, unedited content of file.txt after the conflicting merge, byte for byte (we checked with cat -A to confirm there's no trailing whitespace on the marker lines):
<<<<<<< HEAD
line one from A
=======
line one from B
>>>>>>> branch-b
Three markers, always in this order:
<<<<<<< HEAD— start of "your" version, the branch you rangit mergefrom (here, master/HEAD).=======— the divider between the two versions.>>>>>>> branch-b— end marker, labeled with the name of the branch being merged in.
Everything between <<<<<<< HEAD and ======= is HEAD's content; everything between ======= and >>>>>>> branch-b is the incoming branch's content. Neither git nor anything else removes these lines for you — the file is left exactly like this until you edit it.
3. What git status says during a conflict
We ran git status while the conflict was open. Exact output:
On branch master
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: file.txt
no changes added to commit (use "git add" and/or "git commit -a")
both modified means both branches touched this file since they diverged; that's the phrase to search for when a file is in conflict. Git also tells you directly, in the message, how to proceed or bail out.
4. Resolving it by hand
Open the file, decide what the final content should be, and delete all three marker lines yourself — git does not remove them. We replaced the whole block with a merged line:
# before editing, file.txt has the 5 marker lines from section 2
# we replace all 5 lines with:
line one from A and B combined
Then stage and commit as normal:
git add file.txt
git commit -m "Merge branch-b, resolve conflict"
Note no -m is required — running plain git commit opens an editor pre-filled with a merge commit message. We passed -m to skip that. After committing, git status returned to nothing to commit, working tree clean and git log --oneline --graph showed a normal merge commit joining both branches.
5. Backing out completely with git merge --abort
If you don't want to resolve it, git merge --abort undoes the whole in-progress merge:
$ git merge --abort
$ cat file.txt
line one from A
This restored file.txt to exactly what it was before the conflicting merge started (HEAD's version, no markers), and git status went straight back to nothing to commit, working tree clean. git merge --abort only works while a merge is actually in progress; it's a clean full rollback, not a partial undo.
6. Inspecting a conflict before resolving it
Two commands are useful while markers are still in the file:
$ git log --merge --oneline
22adc26 B edits line
aab3950 A edits line
git log --merge lists the commits that touched the conflicting file on both sides since the branches diverged — useful for finding who to ask.
$ git diff
diff --cc file.txt
index 2baf1ac,b1b0490..0000000
--- a/file.txt
+++ b/file.txt
@@@ -1,1 -1,1 +1,5 @@@
++<<<<<<< HEAD
+line one from A
++=======
+ line one from B
++>>>>>>> branch-b
git diff during a conflict shows a combined ("diff --cc") format against both parents at once, including the literal marker lines as part of the diff content, rather than two normal diffs.
7. Quick checklist
- Run
git status— anything listed asboth modifiedhas conflict markers in it. - Open each file, find
<<<<<<<...=======...>>>>>>>, and manually delete the markers after choosing the content you want. git addeach resolved file, thengit commit(no need for a new message unless you want one).- Changed your mind entirely?
git merge --abortrestores the pre-merge state exactly.
Frequently asked questions
What do <<<<<<<, =======, and >>>>>>> mean in a git merge conflict?
<<<<<<< HEAD starts your current branch's version of the conflicting lines, ======= divides it from the incoming branch's version, and >>>>>>> branchname marks the end, labeled with the branch being merged in. We confirmed this exact order and labeling with git 2.47.3.
How do I know which files have conflicts?
Run git status. In our test it listed the file under 'Unmerged paths' with the label 'both modified'. Files without that label merged cleanly.
Does git remove the conflict markers for me?
No. We verified the markers stay in the file exactly as git wrote them until you manually delete them, choose the final content, then run git add and git commit.
How do I cancel a merge and go back to before it started?
Run git merge --abort. In our test this restored file.txt to its exact pre-merge content and git status immediately showed a clean working tree, with no trace of the attempted merge.
What does git diff show while a conflict is unresolved?
A combined 'diff --cc' format comparing the file against both parent commits at once, including the literal conflict marker lines. git log --merge instead lists the commits from both branches that touched the conflicting file, which helps when you need to ask who wrote which side.
Written with AI assistance. Measured on 2026-10-02 with git 2.47.3 on Linux, plain CLI only (no GUI tool). PlainHeaders is our extension; git is free and open source.