FG
💻 Software🛠️ Developer ToolsMicrosoft

Git: Use VS Code as merge editor

Fresh3 days ago
Mar 14, 20260 views
Confidence Score95%
95%

Problem

1.0.0 introduced the ability to use VS Code as a git difftool. The relevant global `.gitconfig` lines are as follows: [code block] How can I use VS Code as a git mergetool? The relevant arguments it needs to accept, I believe, are `$LOCAL`, `$REMOTE`, `$BASE`, and `$MERGED`.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Configure VS Code as Git Mergetool

Low Risk

The inability to use VS Code as a merge tool in Git is due to the absence of the necessary configuration in the global `.gitconfig` file. While VS Code can be set as a difftool, it requires specific settings to function as a mergetool, which involves defining how it should handle merge conflicts using the appropriate arguments.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Open Global Git Configuration

    Open your terminal or command prompt and access the global Git configuration file to add the necessary settings for VS Code as a mergetool.

    bash
    git config --global -e
  2. 2

    Add VS Code Mergetool Configuration

    In the opened `.gitconfig` file, add the following configuration to set VS Code as the mergetool. This configuration specifies how VS Code should be invoked during a merge conflict.

    ini
    [merge]
    	tool = code
    [mergetool "code"]
    	cmd = "code --wait $MERGED"
    	keepBackup = false
    
  3. 3

    Set Default Mergetool

    Ensure that Git uses VS Code as the default mergetool by adding the following line to your `.gitconfig` file. This will make VS Code the go-to tool for resolving merge conflicts.

    bash
    git config --global merge.tool code
  4. 4

    Test the Mergetool Configuration

    Create a test repository and intentionally create a merge conflict to verify that VS Code launches correctly as the mergetool. Resolve the conflict and ensure that changes are saved properly.

    bash
    git merge <branch-with-conflict>
  5. 5

    Confirm Configuration

    Check the configuration by running the following command to ensure that the settings for the mergetool are correctly applied.

    bash
    git config --global --get merge.tool

Validation

To confirm the fix worked, perform a merge that results in a conflict. When prompted to resolve the conflict, VS Code should open automatically. After resolving the conflict, ensure that the merged file reflects the changes made in VS Code.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

vscodeideeditorfeature-requestgiton-testplanmerge-editor