December 6, 2026

Git Merge Conflicts: How to Read the Markers, Resolve Them, and Avoid the Rebase Trap

Two railway tracks merging at a switch under a red signal

Two branches changed one line in a config file. main set timeout = 45, a feature branch set timeout = 60, and git merge feature stopped with CONFLICT (content): Merge conflict in app.conf. Git didn’t pick a winner because it has no way to know which number is right. What it does give is a precise record of both versions and a set of commands for finishing the job. Every example below was run in a test repository, and the outputs are Git’s own.

Video: Philomatics on YouTube

Why Git stops

Same lines, different changes

Git merges by comparing both branches against their common ancestor. When each side changed different parts of a file, it combines them without asking. In a test with a four-line file, one branch changed line 1 and the other changed line 4, and the merge finished on its own with both changes: a=10 b=2 c=3 d=40.

Adjacent lines count too

Changing line 1 on one branch and line 2 on the other produced a conflict, even though no single line was edited twice. Git treats changes that touch or sit next to each other as one region, because it can’t be sure the two edits don’t depend on each other.

What the merge leaves behind

After the timeout conflict, git status --short showed UU app.conf: unmerged, changed on both sides. Nothing is committed yet. The merge is paused, waiting for a decision.

Listing every conflicted file

In a merge that touches dozens of files, git diff --name-only --diff-filter=U prints only the unmerged ones, one per line, which makes a handy checklist. git ls-files -u goes one level lower and shows the three stored versions of each conflicted file: stage 1 for the common ancestor, stage 2 for the current branch, stage 3 for the incoming one.

Plain beige cardboard or recycled paper texture

Reading the conflict markers

The basic layout

The file now holds both versions:

port = 8080
<<<<<<< HEAD
timeout = 45
=======
timeout = 60
>>>>>>> feature
log_level = info

Git’s merge documentation describes it plainly: “The part before the ======= is typically your side, and the part afterwards is typically their side.” HEAD is the branch being merged into, here main, and the label after >>>>>>> is the branch coming in. Lines outside the markers merged cleanly.

Adding the original with zdiff3

The two-sided view hides one useful fact: what the line said before either change. The same documentation describes an alternate style, “diff3,” which “adds a ||||||| marker and the original text before the ======= marker.” The newer zdiff3 style does the same while trimming lines that match at the edges. With git -c merge.conflictStyle=zdiff3 merge feature, the conflict read:

<<<<<<< HEAD
timeout = 45
||||||| e8bfad0
timeout = 30
=======
timeout = 60
>>>>>>> feature

Now it’s clear both branches raised the timeout from 30. A choice between 45 and 60 is easier to make knowing that. Setting it permanently takes one command: git config --global merge.conflictStyle zdiff3.

The combined diff

git diff during a conflict shows a two-column format, with one + or - column per side. Lines marked ++ exist only in the working file, which is how the markers themselves show up.

Resolving it

Edit, add, commit

The usual fix is editing the file to the final version, deleting every marker line, then:

git add app.conf
git commit

git add is how Git learns a conflict is resolved. It doesn’t check that the file actually makes sense.

Taking one side whole

When one version is simply right, git checkout --theirs app.conf (or --ours) replaces the file with that side. Git’s checkout documentation describes these as checking out “stage #2 (ours) or #3 (theirs)” for unmerged paths. In the test, --theirs gave timeout = 60, and git add plus git commit finished the merge:

*   6c0b96a merge feature, take 60
|\
| * 14978f1 raise timeout to 60
* | 2088a52 raise timeout to 45
|/
* e8bfad0 base config

Backing out

git merge --abort puts things back. The merge documentation says it will “try to reconstruct the pre-merge state,” and warns that uncommitted changes from before the merge may not come back cleanly, so committing or stashing first is safer. In the test, the file returned to timeout = 45 and git status was clean.

Brown rope on brown wooden floor

The rebase trap: ours and theirs swap

Same conflict, rebase instead of merge

Rebasing the feature branch onto main hit the same conflict, but the markers looked different:

<<<<<<< HEAD
timeout = 45
=======
timeout = 60
>>>>>>> fa016d7 (feat 60)

The developer is on the feature branch, yet HEAD holds main‘s value. During a rebase, Git replays the feature commits on top of main, so HEAD is main plus whatever has been replayed so far.

What –ours means now

In the test, git checkout --ours c during the rebase produced timeout = 45, the value from main, and --theirs produced the feature branch’s 60. The checkout documentation warns about exactly this: during a rebase, “ours and theirs may appear swapped,” because --ours gives “the version from the branch the changes are rebased onto.” Someone used to merging who reaches for --ours to keep their own work will throw it away instead.

A safer habit

Reading the file, or the zdiff3 view, before reaching for --ours or --theirs avoids guessing which side is which. git rebase --abort returns everything to the state before the rebase started.

Conflicts that aren’t about lines

Modified on one side, deleted on the other

A file edited on main and deleted on the branch can’t be merged line by line:

CONFLICT (modify/delete): old.txt deleted in x and modified in HEAD.  Version HEAD of old.txt left in tree.

git status --short showed UD old.txt: updated on the current branch, deleted on the incoming one. The resolution is a decision, not an edit: git add old.txt keeps it, git rm old.txt accepts the deletion.

Strategy option -X ours is not the ours strategy

Two similar-looking commands behave very differently. In a test where main changed a to 5 and the branch changed a to 10 and also added a new line:

Command Result
git merge -X ours x a=5 b=2 new=1
git merge -s ours x a=5 b=2

-X ours resolves only the conflicting parts in favor of the current branch and still brings in the branch’s other changes, including new=1. -s ours ignores the other branch’s content completely. The merge documentation warns that -X ours “should not be confused with the ours merge strategy, which does not even look at what the other tree contains at all.” A merge with -s ours records the branch as merged while keeping none of its changes.

Laptop computer turned on

Resolving the same conflict twice

When it keeps coming back

Long-running branches that get rebased or test-merged over and over hit the same conflict each time. Git’s rerere documentation names the fix in its title: “Reuse recorded resolution of conflicted merges.” Once rerere.enabled is set, Git records the conflicted text and the hand resolution, then reapplies that resolution when the identical conflict appears again.

What it looked like

With git config rerere.enabled true, the first merge of the timeout branches printed an extra line, Recorded preimage for 'c'. The conflict was resolved by hand to timeout = 50 and committed. After undoing that merge and running it again, Git printed:

CONFLICT (content): Merge conflict in c
Resolved 'c' using previous resolution.

The file already read timeout = 50.

It still waits for confirmation

Git still reported the merge as failed, and git status --short still showed UU c. The recorded resolution was applied to the file but not staged, so a quick review and git add finish the job. That pause is useful: a resolution that was right last month might not be right after other code changed.

Catching leftover markers

Git will commit them

In one test, the conflicted file went through git add and git commit with all three marker lines still inside. The commit succeeded. Git trusts git add as the sign that the conflict is handled, and a config file or script with <<<<<<< in it will then break wherever it runs.

git diff –check

The git diff documentation describes --check as warning “if changes introduce conflict markers or whitespace errors,” and says it exits with a non-zero status when it finds problems. Run against the staged file before committing:

$ git diff --cached --check
f:1: leftover conflict marker
f:3: leftover conflict marker
f:5: leftover conflict marker

Because of that non-zero exit status, the same command works in a pre-commit hook to block commits that still contain markers.

Small merges conflict less

Long-lived branches drift further from main and collect conflicts. Merging or rebasing often keeps each conflict small enough to read in one screen, and the zdiff3 style makes each one easier to decide.

Sources

  • git-merge documentation, Git: https://git-scm.com/docs/git-merge
  • git-checkout documentation, Git: https://git-scm.com/docs/git-checkout
  • git-diff documentation, Git: https://git-scm.com/docs/git-diff
  • git-rerere documentation, Git: https://git-scm.com/docs/git-rerere

920 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *