# Git Merge Conflicts: Resolve Markers, Ours/Theirs, and Verify the Merge

> Understand Git merge conflict markers, ours/theirs semantics in merge and rebase, safe aborts, rerere, lockfile regeneration, and a verification checklist.

**Quick answer:** A merge conflict means both sides changed the same region, or one side deleted or renamed what the other edited. Git writes markers and leaves three index stages; resolve by intent, not by blindly taking one side. Regenerate lockfiles, grep for leftover markers, run git diff --check and the tests, and merge only with a clean status.

## Key takeaways

- A conflict is a semantic decision, not a text error; the markers are input to your resolution, not the first thing to delete.
- During a merge, ours is HEAD and theirs is the branch being merged; during a rebase that mapping flips, so never apply ours/theirs by habit.
- Lockfiles, generated code, and binaries should be regenerated or selected from one source, never hand-merged line by line.
- rerere, mergetool, and .gitattributes merge drivers reduce repetitive work, but each automation still needs a deliberate review pass.
- A resolution is done only when git ls-files -u, a marker grep, git diff --check, the tests, and git status all come back clean.

---

`git merge` reports `CONFLICT (content)` and leaves a working tree full of `<<<<<<<` markers. The instinct is to delete the markers and commit. That instinct is wrong: the markers encode a decision about behavior, and deleting them only removes the evidence that the decision is still pending.

This guide covers the mechanics behind the markers, the shifting meaning of ours and theirs, safe aborts, lockfile regeneration, and a verification checklist that decides when a resolution is finished.

## What a merge conflict actually is

Git merges by comparing two branch tips and their merge base, the last commit both sides share. If the sides changed different lines, or the same file in separable regions, Git combines them automatically. A conflict appears when both sides changed the same region incompatibly, or when the change is structural rather than textual.

Textual conflicts are only one category. Git also stops on delete/modify, rename/rename, file/directory, mode changes, submodule pointers, and binary files. Some of these leave conflict markers, while others leave one version in the working tree and record the problem only in the index and in `git status`.

That difference matters because removing markers is not a complete resolution. The real definition is: no unmerged index entries, a working tree that implements both sides' intent, and a result that builds and passes tests. Markers are a symptom; a clean index is the required state.

## Merge, rebase, or cherry-pick: choosing the integration

All three operations can conflict, but they preserve and replay history differently. Pick the operation before resolving; switching mid-flight makes conflicts harder.

| Operation | History result | Conflict timing | Use when | Avoid when |
| --- | --- | --- | --- | --- |
| Merge | Preserves both branches and adds a merge commit | Once per merge, against the current tips | Integrating a shared branch and preserving reviewed topology | The branch carries dozens of noisy commits and you need a linear story |
| Rebase | Rewrites commits onto a new base and produces linear history | Once per replayed commit, potentially many times | Cleaning a local feature branch before review | The branch is published and other people built on it |
| Cherry-pick | Copies selected commits as new commits with new hashes | Once per picked commit | Backporting a fix to a release branch | You need the whole branch or continuity of shared history |

A merge resolves the combined result once, but the merge commit can hide mistakes unless it is reviewed against both parents. A rebase replays each commit, so a conflict may reappear several times; `git rerere` exists mostly for this case. A cherry-pick duplicates a change rather than joining histories, so use `-x` and expect the same logical conflict on the next backport.

Practical rules: merge when integrating into a long-lived branch, rebase when tidying unpublished work, and cherry-pick for narrow backports. Never rebase a branch others have pulled without a coordination plan.

## Reading conflict markers and git status

A content conflict writes a block with a `<<<<<<< HEAD` line, the current branch's version, a `=======` separator, the other side's version, and a closing `>>>>>>> branch-name` line. With `merge.conflictStyle=diff3` or `zdiff3`, Git inserts a `|||||||` section with the merge base, often the most useful context because it shows what each side changed.

`git status --short` uses two-letter codes. `UU` means both modified, `AA` both added, `DU` deleted by us, and `UD` deleted by them. A `UU` file has three index stages; a `DU` conflict has no stage 3 because the other side deleted the file.

Inspect the stages directly. The first block below shows the authoritative unmerged list and each stage of one file.

```bash
# List unmerged paths with their index stages
git status --short
git ls-files -u

# Read base, ours, and theirs for one file
git show :1:src/config.ts
git show :2:src/config.ts
git show :3:src/config.ts
```

`git show :1:path` is the base, `:2:` is ours, and `:3:` is theirs. `git ls-files -u` lists every unmerged path with its stage, mode, and blob hash, and it is the authoritative check that a conflict is still unresolved. `git diff` shows a combined diff, but `git diff --ours`, `git diff --theirs`, and `git diff --base` are easier to reason about because they compare the working tree to one stage at a time.

If the markers are missing, or you want the base context back, `git checkout --conflict=diff3 -- src/config.ts` recreates them from the index.

For long hunks, paste each stage into a [diff checker](/tools/diff-checker) to see exactly what each side changed; two aligned panes are easier to read than a combined diff.

## Ours and theirs: semantics flip during rebase

This is the most expensive mistake in this topic. During a merge, `ours` is the branch you are on (`HEAD`) and `theirs` is the branch being merged in. During a rebase, Git checks out the upstream branch and replays your commits on top of it, so `ours` is the upstream base and `theirs` is your own commit being replayed. During a cherry-pick, `ours` is the current branch and `theirs` is the picked commit.

So `git checkout --theirs -- src/config.ts` during a rebase keeps the upstream file, not your work. Teams that learned "theirs is my feature branch" from merges then discard their own changes during a rebase and notice only when tests fail.

Before choosing a side, read the operation header in `git status`, then inspect `git show :2:path` and `git show :3:path`. `git log --merge --left-right -p -- path` shows the commits from each side that touched the file. `git mergetool` labels the stages LOCAL, BASE, and REMOTE, mapping to stages 2, 1, and 3 and avoiding the words ours and theirs entirely.

`git checkout --ours -- path` and `--theirs` take the whole file from one stage, which suits binaries, generated files, and obsolete sides. They are not a resolution strategy for a hunk that needs both sides; they silently drop the other side's intent.

## Resolving by intent, not by marker

Start by reading what each side was trying to do: the surrounding code, the callers, the tests, and the commits shown by `git log --merge`. Two added imports usually mean keep both. One side renaming a function while the other adds a caller means keep the rename and update the caller. A deletion against an edit needs a product decision, not a coin flip.

Write the combined result with both intents represented, then compare it with each parent instead of trusting the editor buffer. `git diff HEAD -- path` shows changes relative to our side; `git diff MERGE_HEAD -- path` shows changes relative to theirs. A correct resolution shows only the deliberate union, not accidental deletions or duplicated blocks.

A bulk [find and replace](/tools/find-replace) can strip marker lines after you have read every hunk, but it must not be the first step: removing a separator before deciding which side survives turns a visible conflict into a silent semantic gap. Use a precise pattern, review the full diff, and never replace content lines together with marker lines.

Stage each file with `git add` only after its hunks are resolved. `git add` removes the unmerged entry and records the resolution; it does not validate it. Repeat until `git ls-files -u` prints nothing.

## Lockfiles, generated files, and binary conflicts

Lockfiles are the classic hand-merge trap. A `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `Cargo.lock`, or `go.sum` conflict is a derived-data conflict: the manifests are the source of truth, and the lockfile is the computed result. Restore one side as a baseline, merge the manifests properly, rerun the package manager, and verify with a frozen install such as `npm ci` or `pnpm install --frozen-lockfile`. Hand-editing integrity hashes or transitive versions produces a lockfile that looks plausible and fails in CI or production.

Generated code and committed build artifacts follow the same rule: merge the generator inputs, regenerate the outputs, and commit only the regenerated result. If the generator embeds timestamps or content hashes, normalize them or accept that the file will conflict on every branch.

Binary files cannot be merged by line. Choose one version with `git checkout --ours -- path` or `--theirs`, or re-export the asset from its source. Submodule conflicts require choosing a commit and running `git submodule update` to confirm the pointer exists.

`.gitattributes` can assign a merge strategy per path: a custom driver for generated files, `merge=union` for append-only changelogs (which may duplicate or interleave entries), and a binary driver for files that must never be text-merged. Automation is safe only when regeneration or validation follows it.

## Automating resolution: rerere, mergetool, and merge drivers

`git rerere` records how you resolved a conflict and replays that resolution when the same conflict appears again. Enable it with `git config --global rerere.enabled true`; `rerere.autoupdate true` also stages resolved paths. It shines during long rebases, but an old resolution can drift after surrounding code changes, so review `git rerere diff` before continuing and use `git rerere forget path` when a recorded resolution is wrong.

`git mergetool` opens a three-way tool per file and writes the merged result back into the working tree. Set `mergetool.keepBackup=false` to avoid `.orig` files, and confirm each file was saved; a GUI that closes without saving leaves the conflict unchanged.

Set `merge.conflictStyle=zdiff3` globally. The base section turns "which of these two blocks looks right" into "what did each side change", which is the actual question.

Custom merge drivers are configured in `.gitattributes` and `git config merge.<name>.driver`. The driver receives base, ours, and theirs files and must exit zero only when it produced a valid result; any other exit leaves the path conflicted. Keep drivers deterministic and test them in CI.

## Aborting and restarting without losing work

While an operation is in progress, `git merge --abort`, `git rebase --abort`, and `git cherry-pick --abort` restore the pre-operation state. They refuse when the checkout would overwrite uncommitted work, which is a safety feature: commit or stash unrelated changes before starting.

`git rebase --skip` discards the commit currently being replayed; use it only when you are certain the change is already present upstream. After resolving a commit during an interactive rebase, `git add` the files and run `git rebase --continue`.

If an abort or a bad reset already lost work, `git reflog` is the recovery tool. `ORIG_HEAD` usually points at the pre-operation tip, and `git reset --hard ORIG_HEAD` restores it, but hard resets discard uncommitted work, so check `git status` first.

Decide early whether to grind or restart. If the conflict spans dozens of files with incompatible refactors, abort, split the branch, and merge in smaller pieces. Repeatedly resolving the same conflict is a signal that the branch lived too long, not a test of endurance.

## Large conflicts and reviewing the merge commit

Large conflicts usually come from long-lived branches, repository-wide formatting, file moves, or generated files mixed with source. Triage by category before editing: lockfiles and generated files go to regeneration, binaries to version selection, mechanical formatting to a formatter, and only the remaining source files need human judgment.

Split the work by file or subsystem so each resolver owns a coherent area, and record the intended behavior in the merge commit message or pull request description. `git checkout -m -- path` recreates the conflict markers from the index if someone staged a half-resolved file by mistake. Resolve in batches and run the fast test subset between batches.

Review the merge commit itself, not just the branch diff. `git show --stat --oneline HEAD` summarizes it; `git diff HEAD^1 HEAD` shows the net change relative to the first parent, and `git diff HEAD^2 HEAD` shows the same relative to the second. Git 2.33 and later can run `git show --remerge-diff HEAD`, which redoes the merge mechanically and shows only what the human resolution changed. That is the cleanest way to spot an accidentally dropped hunk.

When the sides differ mainly in size, a [text statistics](/tools/text-statistics) pass makes the asymmetry obvious: one line against two hundred usually means a branch is stale or generated, and regenerating is cheaper than merging.

## Verification checklist and pass criteria

Run the checks on the merged result, not on either side alone. The table below is the minimum gate before committing or pushing.

| Check | Command | Pass criterion |
| --- | --- | --- |
| No unmerged entries | `git ls-files -u` | No output |
| No leftover markers | `git grep -nE '^(<{7}\|={7}\|>{7})( \|$)'` | No output outside intentional fixtures or documentation |
| No whitespace damage | `git diff --check` | Exit code 0 with no output |
| Index and worktree state | `git status --porcelain` | Only intended files, then empty after the merge commit |
| Tests on the merged tree | project test command | All tests pass, including tests added by either side |
| Lockfile consistency | `npm ci` or `pnpm install --frozen-lockfile` | Exit code 0 and the lockfile is unchanged |
| Merge review | `git show --remerge-diff HEAD` or diffs against both parents | Only intended changes appear |

```bash
# Reject leftover conflict markers in tracked files
git grep -nE '^(<{7}|={7}|>{7})( |$)' -- . ':!*.lock'

# Reject whitespace errors and confirm no unmerged paths remain
git diff --check
git ls-files -u
git status --porcelain

# Validate the merged result, not each side
pnpm install --frozen-lockfile
pnpm test

# Review the merge commit against a mechanical remerge
git show --remerge-diff HEAD
```

The grep is broader than the default markers: it matches seven or more marker characters and allows a trailing label, so it catches `<<<<<<< HEAD` as well as a bare separator. It also matches documentation that quotes markers, the main false positive; exclude those paths instead of weakening the pattern.

Pass criteria are behavioral as well as textual. The tree must build, the full test suite must pass, and any test that covers the two conflicting behaviors must run. A resolution that keeps both sides' code but leaves an unreachable branch, a duplicated initialization, or a variable defined twice can pass a marker grep and still be wrong. Compare the result against both parents and read the merged diff as a reviewer would.

Finally, commit with a message that states how the conflict was resolved and why. The default "Merge branch..." tells the next engineer nothing, while a two-line note about keeping both retry policies and deleting an obsolete flag saves an investigation. After committing, `git status` should be clean and `git log --graph --oneline -5` should show the topology you intended.

## Frequently asked questions

### Why did Git report a conflict when the two branches edited different files?

Git merges cleanly only when changes do not overlap and file identity is stable. Rename/rename, rename/delete, file/directory, mode, and submodule conflicts are reported even when the text never overlaps, because Git cannot infer which name or object should survive. Read the status code before editing anything.

### What do ours and theirs mean during a rebase?

During a rebase, ours is the upstream branch that commits are replayed onto, and theirs is the commit being replayed, which is your own work. This is the opposite of a merge, where ours is your current branch. Check git status and git show :2:path before choosing a side.

### Can I resolve a conflict by deleting the markers?

Deleting markers only removes the syntax; it does not make the combined code correct. You still need to keep both sides where both changes matter, drop a side only when it is obsolete, and confirm the result compiles and passes tests. A marker grep after editing catches regions you skipped.

### How do I abort a merge, rebase, or cherry-pick safely?

Use git merge --abort, git rebase --abort, or git cherry-pick --abort while the operation is still in progress. Each restores the pre-operation state, but abort refuses if it would overwrite uncommitted work, so commit or stash first. If an abort already lost work, recover it through git reflog or ORIG_HEAD.

### Should I resolve a lockfile conflict by hand?

No. Choose one side to restore a syntactically valid baseline, rerun the package manager so the lockfile is regenerated from the merged manifests, then install with a frozen-lockfile mode. Hand-editing a lockfile usually leaves integrity hashes or transitive versions inconsistent with the manifests.

## References

- [Git: git-merge documentation](https://git-scm.com/docs/git-merge)
- [Pro Git book](https://git-scm.com/book/en/v2)
- [Git: git-rerere documentation](https://git-scm.com/docs/git-rerere)
- [Git: git-diff documentation](https://git-scm.com/docs/git-diff)

---

- Canonical: https://www.jsonmind.com/guides/git-merge-conflict-resolution
- Locale: en
- Published: 2026-11-17
- Updated: 2026-11-17
- Tools: diff-checker, find-replace, text-statistics