Fix Merge Conflicts

The symptom

You ran git merge (or git pull) and instead of a friendly success message, Git printed something like this and stopped:

What Git prints

Terminal
$ CONFLICT (content): Merge conflict in src/app.js
$ Automatic merge failed; fix conflicts and then commit the result.
In VS Code
  1. The Source Control panel lists the file under a new section called Merge Changes
  2. The file gets a ! badge, and the Source Control icon in the sidebar shows a count

This is Git's message, not commands to run.

What it means

First, breathe — nothing is broken and nothing is lost. A conflict isn't an error. It happens when two branches changed the same lines of the same file, and Git — which never guesses about your code — pauses to ask a question only a human can answer: which version do you want? Your job is simply to answer it, then let Git finish.

main merge feature
A conflict happens on the way to this merge commit — resolving it lets Git finish the join.

Read the markers

Git shows you exactly where the disagreement is by writing conflict markers into the file. Both versions are right there, stacked one above the other:

What a conflict looks like in the file

Terminal
$ <<<<<<< HEAD
$ your version of the line
$ =======
$ the other branch's version
$ >>>>>>> feature-login
In VS Code
  1. VS Code highlights the conflict and shows buttons: Accept Current, Accept Incoming, or Accept Both
  2. Click the one you want (or edit the text by hand to combine them)
  3. Remove the <<< marker lines if you edit manually

These markers are inserted into your file by Git; they are not commands to run.

Mental model: a conflict is a fill-in-the-blank form, not a fire. Git found two answers for the same line, wrote both into the file, and is waiting for you to cross one out. There is no timer — take your time.

Fix it in VS Code — the Merge Editor

You can edit the markers by hand in any editor, but VS Code has a purpose-built Merge Editor that shows both versions side by side and builds the final result for you. Once every conflict is resolved, you finish the merge the normal way: stage and commit.

Resolve, then finish the merge

Terminal
$ # after fixing each conflicted file:
$ git add .
$ git commit
In VS Code
  1. Click the file under Merge Changes in the Source Control panel
  2. Click Resolve in Merge Editor (button, bottom-right of the editor)
  3. You'll see three panes: Incoming (their version), Current (yours) and Result (the final file, at the bottom) — for each conflict click Accept Incoming, Accept Current or Accept Combination
  4. Click Complete Merge, then commit with the ✓ Commit button — VS Code pre-fills a merge message

git commit without -m opens an editor with a pre-written merge message — just save and close it.

For a quick one-line conflict, you don't even need the Merge Editor: VS Code shows small inline links right above the markers — Accept Current Change | Accept Incoming Change | Accept Both Changes. One click picks the version and removes the markers for you.

Bail out safely

Halfway through and it feels wrong? You never have to finish a merge. One command rewinds everything to the moment before you started, conflicts and all.

Cancel the merge entirely

Terminal
$ git merge --abort
In VS Code
  1. Open the Command Palette (Ctrl+Shift+P)
  2. Type Git: Abort Merge and press Enter

Your branch returns to exactly how it was before the merge. Nothing is lost.

Escape hatch: there is no point in a merge where you're trapped. Until you commit the result, git merge --abort is always available — resolve the conflict tomorrow with fresh eyes if you like.

Conflicts outside merges

Merges aren't the only place this happens. git pull (which merges behind the scenes), git stash pop and git rebase can all raise the identical situation: same markers, same fix — resolve, stage, continue. The abort command just changes name (git rebase --abort, for instance). You'll meet one of these in Stashing.

Up next: shelving half-finished work so you can switch tasks without committing — Stashing Changes.

FAQ

Frequently Asked Questions

How do I fix a merge conflict?
Open each marked file and choose the right content between the <<<<<<< and >>>>>>> markers — VS Code's Merge Editor shows Accept buttons for each conflict. Then git add the files and git commit to finish the merge.
How do I cancel a merge that has gone wrong?
git merge --abort returns everything to exactly how it was before you started the merge. In VS Code, run Git: Abort Merge from the Command Palette. Nothing is lost.
Why do merge conflicts happen?
Two branches changed the same lines of the same file, so Git can't decide which version to keep and pauses to ask you. It's a question, not an error — git pull, git stash pop and git rebase can raise the same one.
Does a conflict mean I lost work?
No — both versions are preserved right there in the file, between the <<<<<<< and >>>>>>> markers. Nothing is deleted until you choose what to keep, and git merge --abort rewinds the whole merge.