Chapter 3.3 — Resolve in VS Code☕ 18 min read

Resolve in VS Code

VS Code ke 4 buttons: Current, Incoming, Both, Compare. Simple click karo, code review karo, git add karo, commit karo.

01VS Code Inline Resolution Buttons

VS Code detects conflict markers automatically and shows inline buttons above each conflict section. No need to manually delete markers line by line.

Four options appear above every conflict:

  • Accept Current Change — keeps your version (the HEAD side), removes the incoming version and all markers.
  • Accept Incoming Change — keeps their version (the branch you are merging), removes your version and all markers.
  • Accept Both Changes — places both versions sequentially in the file. You will usually need to edit the result.
  • Compare Changes — opens the 3-way merge editor for side-by-side comparison and manual editing.

Clicking a button replaces the entire conflict section — from <<<<<<< to >>>>>>> — with the chosen version. The markers are removed automatically.

This is the fastest way to resolve simple conflicts where you clearly want one side. For complex conflicts, use the 3-way merge editor instead.

# VS Code shows these buttons above each conflict:
# [Accept Current Change] [Accept Incoming Change]
# [Accept Both Changes]   [Compare Changes]

# Click "Accept Current Change" to keep your version
# Before:
<<<<<<< HEAD
console.log("v2");
=======
console.log("v1");
>>>>>>> feature
# After clicking "Accept Current Change":
console.log("v2");
# Markers removed, your version kept!
The buttons appear ONLY when VS Code detects valid conflict markers. If you manually edit the markers and break their format, the buttons disappear. Always let VS Code handle marker removal — never delete them manually when using the inline buttons.
02The 3-Way Merge Editor

Click Compare Changes to open the 3-way merge editor (available in VS Code 1.59+). This is the most powerful conflict resolution tool in VS Code.

Three panels appear side by side:

  • Incoming (left) — the version from the branch you are merging in (theirs).
  • Result (center) — the editable merged output. This is where you build the final version.
  • Current (right) — your version (the HEAD side, yours).

You can edit the Result panel directly to combine changes from both sides. Checkboxes next to each change let you include or exclude specific lines.

This is ideal for complex conflicts where you need to see all versions simultaneously and craft a combination that preserves logic from both sides.

The 3-way editor gives you full control over exactly what goes into the final version — no surprises, no blind acceptance.

# Opening the 3-way merge editor:
# 1. Click "Compare Changes" on the inline conflict, OR
# 2. Click the "C" or "Conflicting File" icon in Source Control

# Layout:
# +---------------+---------------+---------------+
# |   Incoming    |    Result     |   Current     |
# |  (theirs)     |  (editable)   |   (yours)     |
# |  port: 8080   |  port: ???    |  port: 3000   |
# +---------------+---------------+---------------+

# Edit the Result panel to create the final version:
# port: process.env.PORT || 3000
💡 Pro Tip: Use the 3-way merge editor when a conflict involves logic changes on both sides. Inline buttons are fine for simple "pick one side" conflicts, but the 3-way editor lets you combine the best of both versions with full visibility.
03Configuring VS Code as Merge Tool

Set VS Code as Git's default merge tool so that git mergetool opens files directly in VS Code.

Two configuration commands are needed:

  • git config --global merge.tool vscode — tells Git to use a tool named "vscode".
  • git config --global mergetool.vscode.cmd 'code --wait $MERGED' — tells Git the exact command to run.

The --wait flag is crucial: it keeps the terminal paused until you close the VS Code tab, signaling that you are done resolving.

Running git mergetool opens each conflicted file in VS Code one by one. After resolving and saving, close the tab — the terminal automatically moves to the next conflict.

You can also disable backup files that mergetool creates with git config --global mergetool.keepBackup false.

# Set VS Code as your merge tool
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd 'code --wait $MERGED'

# Alternative: Use VS Code built-in Git UI instead
# No configuration needed — just open the folder in VS Code

# Using git mergetool from terminal
git mergetool
# Opens each conflicted file in VS Code
# Resolve, save, close tab
# Terminal automatically moves to next conflicted file

# To disable the backup files mergetool creates
git config --global mergetool.keepBackup false
You do not NEED to configure mergetool to use VS Code for conflict resolution. Simply opening your project folder in VS Code and using the inline buttons or 3-way editor works perfectly. The git mergetool configuration is only needed if you prefer launching the editor from the terminal.
04Post-Resolution: Don't Forget to Add and Commit

After resolving conflicts in VS Code, the file is modified but NOT staged. This is the most common mistake developers make after resolving conflicts.

You must run git add <resolved-file> to tell Git the conflict is resolved. Without this, Git still considers the file conflicted.

After adding, git status will show the file as "modified" instead of "unmerged" — confirming the resolution was registered.

Once all conflicts are resolved and added, run git commit to complete the merge. Git auto-generates a merge commit message.

VS Code's Source Control panel also lets you stage and commit with a click — but the git add step is still required, whether you do it from the terminal or the UI.

If you accidentally save a file with conflict markers still in it, Git will warn you when you try to commit.

# Step 1: Resolve all conflicts in VS Code
# Step 2: Save the file

# Step 3: Stage the resolved file
git add app.js
# OR stage all resolved files at once:
git add .

# Step 4: Verify no conflicts remain
git status
# "All conflicts fixed but you are still merging."

# Step 5: Complete the merge with a commit
git commit
# Git auto-generates a merge commit message
# Save and close the editor to complete
Git uses the staging area to track conflict resolution. Until you git add the file, Git still sees it as conflicted (unmerged). The git add is not just staging — it is a declaration that the conflict is resolved. This is why the step cannot be skipped.
05Other Merge Tools Beyond VS Code

VS Code is not the only option for conflict resolution. Several dedicated merge tools exist, each with different strengths.

  • Beyond Compare — Powerful visual diff and merge tool. Paid, cross-platform. Industry standard for many teams.
  • Meld — Free, open-source visual diff tool. Available on Linux and Windows. Clean, simple interface.
  • KDiff3 — Free diff and merge tool with automatic merge support. Can resolve simple conflicts automatically.
  • IntelliJ IDEA — Built-in 3-way merge editor. Excellent if you already use JetBrains IDEs.
  • Vimdiff — Terminal-based 3-way merge. For Vim power users who never leave the terminal.

The best merge tool is the one you are comfortable and fast with. During a merge conflict, you need confidence and speed — not a learning curve.

Use git mergetool --tool-help to see which tools Git can find on your system.

# Configure Beyond Compare
git config --global merge.tool bc
git config --global mergetool.bc.path "/usr/local/bin/bcomp"

# Configure Meld
git config --global merge.tool meld
git config --global mergetool.meld.cmd 'meld "$LOCAL" "$BASE" "$REMOTE" "$MERGED"'

# Configure KDiff3
git config --global merge.tool kdiff3

# List available merge tools
git mergetool --tool-help

# Use a specific tool for one merge
git mergetool --tool=meld
💡 Pro Tip: You can use different tools for different situations. git mergetool --tool=meld uses Meld for just the current merge without changing your global config. Use VS Code for quick conflicts and a dedicated tool like Beyond Compare for complex multi-file merges.

Lo kar liya — Key Points:

  • ✅ VS Code shows inline buttons above conflicts: Accept Current, Accept Incoming, Accept Both, Compare
  • ✅ The 3-way merge editor (Compare Changes) shows Incoming, Result, and Current side by side for complex resolutions
  • ✅ Configure VS Code as merge tool with git config --global merge.tool vscode and use git mergetool to open files
  • ✅ After resolving in the editor, you MUST git add the file to mark the conflict as resolved
  • ✅ Once all conflicts are added, run git commit to complete the merge
  • ✅ "Accept Both Changes" just concatenates — you will usually need to edit the result for logical correctness
Course Search
Search across all chapters & stages
📖

Search the course

Type any topic — branching, stash, rebase, hooks — and jump straight to that chapter.

merge branchesgit stashundo commitrebase