How to Resolve Git Merge Conflicts Without Fear
A merge conflict isn't Git breaking. It's Git asking you a question it can't answer alone. Here's how to answer it calmly, every time.
Key takeaways
- Run git status to list files marked both modified, edit each one to keep the code you want, and delete every conflict marker.
- Then git add the file and run git commit, or git rebase --continue during a rebase.
- Set merge.conflictStyle to zdiff3 to see the common ancestor, and use git merge --abort to back out.
On this page
To resolve a Git merge conflict, run git status, open each file listed as both modified, edit the block between <<<<<<< and >>>>>>> into the code you want, delete the markers, then git add the file and git commit (or git rebase --continue). If it is the wrong moment, git merge --abort puts everything back.
Verified against
Git 2.56.0, against the git-scm.com reference pages for git-merge, git-rerere and git-mergetool. Checked October 2026.
The first time I hit a merge conflict I closed the terminal and hoped it would go away. It did not. The branch sat there half-merged for two days until a senior engineer walked over, fixed it in a couple of minutes, and moved on. What looked like a wall was a five-minute task I didn't understand yet.
A conflict happens when two branches change the same lines of the same file, and Git has no way to know which version you want. Git is good at merging changes that don't overlap. Two people editing different functions in the same file? Merged automatically, no drama. But when both sides touch the same line, Git stops and hands the decision back to you. That's the whole thing. It isn't an error. It's Git refusing to guess.
Seeing what actually conflicted
When a merge or pull stops with a conflict, the first command is always the same:
$ git merge feature/pricing
Auto-merging src/checkout.js
CONFLICT (content): Merge conflict in src/checkout.js
Automatic merge failed; fix conflicts and then commit the result.
$ git status
On branch main
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: src/checkout.js
both modified is the label that matters. Those are the files you have to open. Everything else Git already handled. On a big merge you might have three conflicted files out of forty, so don't panic at the size of the merge, only at the count under "Unmerged paths."
Reading the markers
Open a conflicted file and you'll find Git has stuffed both versions inline, wrapped in markers:
function taxRate(region) {
<<<<<<< HEAD
return region === 'EU' ? 0.21 : 0.08;
=======
return REGION_TAX[region] ?? 0.10;
>>>>>>> feature/pricing
}
Three markers, and each means something specific. <<<<<<< HEAD opens the version from your current branch, the one you had checked out. ======= is the divider. >>>>>>> feature/pricing closes the version coming in from the branch you're merging. So the top block is "mine," the bottom block is "theirs."
Your job is to edit this into the single correct answer and delete all three markers. Sometimes you keep the top, sometimes the bottom, and often you write something new that takes the best of both:
function taxRate(region) {
return REGION_TAX[region] ?? 0.08;
}
The markers have to go completely. A leftover ======= will get committed and break the file, and worse, it'll compile in some languages before failing somewhere confusing. I check for leftovers across the repo before I commit any conflict resolution. It has caught me more than once:
$ git diff --check
$ git grep -n -e '^<<<<<<< ' -e '^>>>>>>> '
git diff --check flags leftover conflict markers in unstaged changes; the git grep catches anything already staged or committed.
Finishing the merge
Once the file reads the way you want, you tell Git this path is resolved:
$ git add src/checkout.js
$ git status
All conflicts fixed but you are still merging.
$ git commit
For a plain merge, git commit with no arguments opens a prepared merge message and you're done. If the conflict happened during a rebase instead, the command is git rebase --continue. During a cherry-pick, it's git cherry-pick --continue. Same shape every time: fix the file, git add, then continue.
Turn on a better conflict style
This is the one setting that changed how I feel about conflicts. By default Git shows you "mine" and "theirs" but not the common ancestor, so you're guessing what each side was trying to change. Switch to diff3, or zdiff3, which is the same thing minus the lines both sides already agree on, and it shows all three:
$ git config --global merge.conflictStyle zdiff3
Now a conflict includes the original:
<<<<<<< HEAD
return region === 'EU' ? 0.21 : 0.08;
||||||| merged common ancestor
return 0.08;
=======
return REGION_TAX[region] ?? 0.10;
>>>>>>> feature/pricing
That middle block is the answer key. You can see the base was a flat 0.08, one side added an EU case, the other side moved to a lookup table. Now the merge is obvious: keep the table, default it to 0.08. Without the ancestor you'd have stared at two rewrites with no idea what changed from what. I set this on every machine I touch.
Tools that help
You don't have to edit raw markers. git mergetool launches a configured three-pane tool. VS Code is my daily driver here: open the conflicted file and it gives you "Accept Current," "Accept Incoming," and "Accept Both" buttons right above each block, plus a merge editor with a result pane. For anything mechanical it's faster than editing by hand. For anything subtle I still read the diff3 markers, because buttons make it too easy to accept a side without thinking.
When you just want out
Sometimes you start a merge, see the mess, and decide it's not the moment. You can back out cleanly:
$ git merge --abort
That returns you to where you were before the merge started, no half-finished state. The one catch, from the git-merge docs: uncommitted changes you had before starting the merge may not come back intact, so commit or stash before you merge anything non-trivial. During a rebase the escape hatch is git rebase --abort. Knowing these exist is half of why conflicts stop being scary. Nothing you do mid-merge is permanent until you commit.
Making them rarer
Conflicts are a function of how long branches drift apart. The longer two branches live without seeing each other, the more the same lines diverge. So pull from the main branch often, keep pull requests small enough to merge in a day or two, and say something in chat when you're about to refactor a file half the team touches. Most brutal conflicts I've untangled came from a two-week branch meeting a big reformatting commit. That's an organizational problem wearing a Git costume.
For repeated conflicts, Git has rerere (reuse recorded resolution). Turn it on with git config --global rerere.enabled true and Git remembers how you resolved a given conflict. Next time the same hunk collides, during a repeated rebase or a long-lived branch, it replays your resolution into the working tree. It deliberately leaves the index alone, so you still review with git diff and git add yourself. It quietly saves real time on gnarly rebases, and if you are choosing between the two workflows, git rebase vs merge covers when each one makes conflicts worse.
If you want a broader map of Git failure modes beyond merges, our Git troubleshooting guide covers the rest of the error messages that make people close the terminal.
Questions people ask
How do I accept all incoming changes in a Git merge conflict?
For a whole file, run git checkout --theirs path/to/file to take the incoming branch's version, or git checkout --ours path/to/file to keep yours, then git add it. For the whole merge, git merge -X theirs branch resolves conflicting hunks in favor of the incoming side. Be careful during a rebase: "ours" and "theirs" swap, because the branch being replayed is "theirs".
How do I undo a merge that has conflicts?
Before you commit, run git merge --abort. It reconstructs the pre-merge state and is equivalent to git reset --merge when a merge is in progress. During a rebase use git rebase --abort, and during a cherry-pick git cherry-pick --abort. If you already committed the merge, that is a different problem: use git reset --hard ORIG_HEAD locally, or git revert -m 1 on a pushed merge commit.
What is the difference between diff3 and zdiff3?
Both add a ||||||| section showing the common ancestor between your side and theirs, which makes intent visible. zdiff3 also trims lines that match on both sides at the start or end of the conflict region, so the conflict block is shorter. Set it with git config --global merge.conflictStyle zdiff3; the default style, merge, shows no ancestor at all.
The call we'd make
Turn on zdiff3 today, on every machine, before you hit your next conflict. Seeing the common ancestor turns most conflicts from a guess into a decision. Add rerere if you rebase long branches. Then treat conflicts as what they are: Git asking a question only you can answer, with --abort always sitting there as a free undo. Once you trust the undo, the fear goes away and it's just editing.
Sources
Cite this article
Kiril Urbonas (2026). How to Resolve Git Merge Conflicts Without Fear. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/fix-git-merge-conflict
[How to Resolve Git Merge Conflicts Without Fear](https://www.devopsness.com/blog/fix-git-merge-conflict) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from DevOps
Explore more articles in this category
kaniko CVE-2026-105769: Lookalike ACR Hosts Get Your Azure Token. Rebuild on v1.25.20
A FROM line pointing at a host like x.azurecr.io.attacker.com is enough to make kaniko hand the build's Entra ID token to that host. Which kaniko forks and images are affected, how to find Azure identities in your build pods, and what to rotate.
Sign Container Images With Cosign: Keyless GitHub Actions Workflow, SBOM and In-Cluster Checks
One workflow that builds, signs keylessly with GitHub OIDC, attaches an SBOM and SLSA provenance, plus the Kyverno policy that refuses anything unsigned. Copy it, change three names, ship it.
GitLab CVE-2026-110264: A Second CVSS 10 RCE in Nine Days. Patch to 19.5.1
An unauthenticated regex-compiler RCE reaching back to GitLab 7.0, no workaround, and backports on older branches that fix only the critical bug. The exact version per branch and the commands to get there.
You might have missed
Evergreen posts worth revisiting.