Most bad conflict resolutions aren't caused by hard conflicts. They're caused by Git's default output, which shows you two versions of a block and leaves out the third one, the version both sides started from. Without it you are guessing which side changed what, and "keep mine" is the guess most people make at 6 PM.
Three settings and one habit fix most of this:
git config --global merge.conflictStyle zdiff3 # show the base version in every conflict (Git 2.35+)
git config --global rerere.enabled true # remember how you resolved each conflictThe habit is knowing that during a rebase, "ours" and "theirs" swap places. The rest of this post shows why each one matters, using real output from a throwaway repo.
The conflict Git shows you by default
Two branches both edited the same object. main raised the timeout and added a backoff setting. feature raised the timeout and the retry count. Merge feature into main and you get this:
const config = {
<<<<<<< HEAD
timeout: 10000,
retries: 3,
backoff: "exponential",
=======
timeout: 5000,
retries: 5,
>>>>>>> feature
region: "us-east-1",
};Read it cold and answer: did feature change retries, or did main? Is retries: 3 a deliberate value someone set on main, or just what was there before? You can't tell from this. Both blocks are just "the current state of each side", so every line looks like a decision.
Turn on zdiff3 and the answer appears
Same merge with merge.conflictStyle=zdiff3:
const config = {
<<<<<<< HEAD
timeout: 10000,
retries: 3,
backoff: "exponential",
||||||| b4f7228
timeout: 3000,
retries: 3,
=======
timeout: 5000,
retries: 5,
>>>>>>> feature
region: "us-east-1",
};The new middle section, between ||||||| and =======, is the merge base: the code as it was before either branch touched it. Now each line explains itself:
| Line | Base | main (HEAD) | feature | What happened | Resolution |
|---|---|---|---|---|---|
timeout | 3000 | 10000 | 5000 | Both changed it | A real decision: ask someone |
retries | 3 | 3 | 5 | Only feature changed it | Take 5 |
backoff | (none) | "exponential" | (none) | Only main added it | Keep it |
So the correct result keeps feature's retries, keeps main's backoff, and flags the timeout for a human. Without the base section, "keep HEAD" looks reasonable and silently throws away the retry change. With it, there's exactly one line that needs a judgment call, and you can see which one.
The base section turns "which side is right?" into "what did each side change?". The second question almost always has a mechanical answer. Only lines that both sides changed need a human.
diff3 vs zdiff3
diff3 is the older style that also shows the base. zdiff3 ("zealous diff3", added in Git 2.35) does the same thing but moves lines that both sides changed identically out of the conflict. In a second test where both branches added the same two lines and then diverged on one line, plain diff3 put all four lines on each side of the conflict. zdiff3 produced this:
a
shared1
shared2
<<<<<<< HEAD
MAIN
||||||| dcdb7e8
b
=======
FEATURE
>>>>>>> feature
b2
cSmaller conflicts, same information. If you're on Git older than 2.35 (check with git --version), use diff3. Your merge tool may show a three-pane view anyway, but the marker style also controls what lands in the file for anyone editing it in a plain editor.
The ours/theirs swap during a rebase
During git merge feature on main, "ours" is main (where you are) and "theirs" is feature (what you're bringing in). Intuitive.
During git rebase main on feature, it flips. Git checks out main and replays your commits on top of it, one at a time. So HEAD is the upstream branch, and your own commit is the thing being applied. Here's the same conflict mid-rebase:
<<<<<<< HEAD
MAIN
=======
FEATURE
>>>>>>> 26041f4 (feat)HEAD is main's code. Your work is at the bottom, labeled with your commit's hash and message.
During a rebase,
--oursmeans the branch you're rebasing onto, and--theirsmeans your own commits. Runninggit checkout --oursto "keep my changes" mid-rebase does the opposite and discards them.
The same swap applies to git pull --rebase, and to -X ours / -X theirs passed to a rebase. Read the label after >>>>>>>, not the word: if it's your commit message, that's your side. If you already resolved a rebase the wrong way round, the commits from before the rebase are still in the reflog. Recovering them with git reflog takes about a minute.
Four commands that look like "keep my side" and aren't the same
These get mixed up constantly. I ran each one against the same two branches, where main changed x and y in one file, and feature changed x in that file and also added a line to a second, non-conflicting file.
git checkout --theirs <file> replaces the whole file
It doesn't resolve the conflicts. It throws the file away and takes the other side's entire version. In the test, that kept feature's x = 2, but it also reverted main's unrelated, non-conflicting y = 3 back to y = 1. Fine for generated files and lockfiles. Dangerous for source files, because the non-conflicting changes vanish without any marker telling you.

That's how a "resolved" merge passes review and quietly reverts someone's bug fix from two weeks ago.
git merge -X ours resolves only the conflicting hunks
The strategy option -X ours lets Git merge everything it can automatically and only picks your side where hunks actually conflict. In the test, x and y came from main, and feature's new line in the other file was still merged in. This is usually what people mean by "prefer my side".
git merge -s ours ignores the other branch completely
The strategy -s ours (no -X) records a merge commit but keeps your tree exactly as it was. feature's new line in the second file was gone. Git now believes feature is merged, so future merges won't bring those changes in either. It exists for deliberately superseding a branch, not for resolving conflicts. One letter of difference from -X ours.
git checkout --conflict=zdiff3 <file> starts over
If you mangled a file mid-resolution, this puts the conflict markers back, with the base section, so you can try again without aborting the whole merge. In the test, Git labeled the sides ours, base and theirs instead of branch names. git merge --abort (or git rebase --abort) is the full reset when everything has gone sideways.
rerere: resolve a conflict once
rerere stands for "reuse recorded resolution". With rerere.enabled on, Git saves the conflicted hunk and how you resolved it. The next time the identical conflict appears, it applies your resolution for you:
$ git merge feature
Auto-merging f
CONFLICT (content): Merge conflict in f
Recorded preimage for 'f'
...
$ git commit
Recorded resolution for 'f'.
# later: the same conflict again, after a reset, rebase, or re-merge
$ git merge feature
Auto-merging f
CONFLICT (content): Merge conflict in f
Resolved 'f' using previous resolution.Where this pays off:
- Long-lived branches you rebase repeatedly. The same conflict against
maincomes back on every rebase. With rerere, you fix it once. - Test merges. Merge
maininto your branch to check for conflicts, resolve them, then throw the merge away. When you do the real merge or rebase later, the resolutions are already recorded. - Re-running an interactive rebase after you got the commit order wrong. Covered in more depth in the interactive rebase guide.
Note that rerere fixes the file but leaves it unstaged: git status still shows UU. That's deliberate, so you look at the result before git add. If you trust it, rerere.autoUpdate=true stages it too. Recorded resolutions live in .git/rr-cache/ and expire after 60 days by default (gc.rerereResolved). If one turns out to be wrong, git rerere forget <file> drops it.
Files you should never hand-merge
Some conflicts aren't worth reading at all:
- Lockfiles (
package-lock.json,pnpm-lock.yaml,Cargo.lock,poetry.lock). Take one side whole, then regenerate:git checkout --ours pnpm-lock.yaml && pnpm install. Hand-merged lockfiles produce trees no package manager would ever write. - Append-only files like a changelog where both sides added entries at the end. A line in
.gitattributessuch asCHANGELOG.md merge=uniontells Git to keep both sides' lines without conflict markers. The gitattributes docs warn that this can leave lines in an odd order, so only use it where order doesn't matter much. - Generated code (compiled output, snapshots, OpenAPI clients). Resolve the source, then rerun the generator.
If you get the same conflicts in structured files like JSON or YAML, or in code where two branches added different imports or functions next to each other, Mergiraf is worth a look. It's a syntax-aware merge driver you register in .gitattributes, and it resolves conflicts that are only "conflicts" because the lines were adjacent.
A checklist for the conflict in front of you
- Find all of them:
git diff --name-only --diff-filter=Ulists every conflicted file. Don't trust that you saw them all scrolling past. - Read the base. If you don't have zdiff3 on yet,
git checkout --conflict=zdiff3 <file>adds it to the file you're looking at. - Resolve per line, not per side. Only lines changed on both sides need a decision.
- Search for leftover markers before you commit:
git diff --check(orgit diff --cached --checkonce you have rungit add) flags conflict markers left in the file. Committing a stray=======into a YAML file is how the pipeline finds out first. - Run the tests. A textually clean merge can still be semantically broken, for example when one branch renamed a function and the other added a new call to the old name. Git can't see that.
When you're stuck with a conflicted snippet outside a repo (a pasted diff, a file someone sent you, a CI log), the Git Conflict Remover strips the markers and keeps ours, theirs, both or neither for every block, and it understands the base section if you paste a zdiff3 conflict.
Wrapping up
Merge conflicts are mostly a visibility problem. The default markers show two outcomes with no history, so people pick a side. With the base version visible, most conflicts resolve themselves line by line, and the few real decisions are obvious. Add rerere so you only make each decision once, and remember that during a rebase your own work is "theirs".
If you want to check a three-way merge by hand before you run it, paste the base and both versions into the 3-way diff and merge viewer and it shows which lines merge cleanly and which ones actually conflict.
Cover photo by Raj Gautam on Pexels.
