Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Concepts

Merge conflict markers

Read Git conflict markers (<<<<<<<, =======, >>>>>>>), understand the diff3 and zdiff3 styles, and resolve, abort or redo a conflicted merge step by step.

A merge conflict happens when both sides changed the same lines (or one side changed a file the other deleted) and Git cannot decide which version to keep. Git stops, writes both versions into the file between conflict markers and waits for you. Nothing is lost: the merge is simply unfinished until you tell Git the result.

TEXT
<<<<<<< HEAD
the line on your branch
=======
the line on the branch being merged
>>>>>>> feature

Everything between <<<<<<< and ======= is your side ("ours"); everything between ======= and >>>>>>> is the other side ("theirs"). Edit the file so that only the final text remains, delete the three marker lines, then git add the file and finish with git commit (or git merge --continue).

Try it

Bash Create, read and resolve a conflict

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash diff3 style shows the common ancestor

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Marker Meaning
<<<<<<< HEAD start of your side; the label is the current branch or HEAD
||||||| base start of the common ancestor text (only in diff3 and zdiff3 styles)
======= divider between the two sides
>>>>>>> name end of the other side, labelled with the branch or commit being merged

Style is set with merge.conflictStyle: merge (default, two sides), diff3 (adds the base) and zdiff3 (like diff3 but moves lines both sides share outside the markers, making conflicts smaller).

Usage notes

  • Base text helps most. With diff3 you can see what each side changed rather than just two finished versions, which makes resolution much easier. Many people set it globally.
  • Whole-file shortcuts. git checkout --ours file or --theirs file takes one side entirely. During a rebase the meaning is swapped: "ours" is the branch you are rebasing onto and "theirs" is your own commit being replayed.
  • Strategy options such as -X ours/-X theirs resolve only the conflicting hunks automatically, which is easy to misuse; the choice happens silently.
  • Find what is left. git diff --name-only --diff-filter=U lists unmerged files, and git grep -n '^<<<<<<<' finds forgotten markers. A commit hook can reject them.
  • Binary and delete/modify conflicts produce no markers: pick a side with git checkout --ours/--theirs, or git rm / git add to decide the file's fate.
  • Start over. git merge --abort restores the pre-merge state; git checkout -m file recreates the markers for one file if you resolved it badly.
  • Remember resolutions. rerere.enabled lets Git replay a resolution you made before, useful for repeated rebases.
  • Tools. git mergetool opens your configured visual merge tool.