Igor Kulman

Using Visual Studio Code as Git merge tool

· Igor Kulman

Visual Studio Code is a neat editor with many good functionalities but I especially like the way it shows Git merge conflicts. Instead of a 2-way or a 3-way split it just shows one window with both changes, nicely highlighted with colors and actions.

Merge conflict in VSCode

I like this feature so much I decided to set Visual Studio Code as my Git merge tool for both the command line and Git Tower.

Command line

Using Visual Studio Code as a merge tool for Git when using command line means editing your .gitconfig. You just need to define a new tool called code and set it as the default merge tool.

        tool = vscode
[mergetool "vscode"]
        cmd = code --wait $MERGED

Merge tool for Git Tower

If you use Git Tower as you GUI client for Git, adding Using Visual Studio Code as a merge tool is a bit more tricky, but there is documentation showing you how to do it. You need to create a CompareTools.plist file in ~/Library/Application Support/com.fournova.Tower2/CompareTools/. This file contains definitions for all the custom diff and merge tools you want to use, not just Visual Studio Code.

The definition for Visual Studio Code may look like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
<plist version="1.0">
        <string>Visual Studio Code</string>
        <string>Visual Studio Code</string>

It calls a bash script code.sh when invoked, that runs Visual Studio Code with the same parameters as in the Git merge tool definition in .gitconfig, it is just referenced a differently.


code --wait $4

Do not forget to make the bash script runnable by calling chmod +x code.sh.

When you restart Git Tower, you will now see Visual Studio Code among the merge tools options.

Setting VSCode as merge tool in Git Tower

See also