How to use Visual Studio Code as default editor for git?

In the most recent release (v1.0, released in March 2016), you are now able to use VS Code as the default git commit/diff tool. Quoted from the documentations:

  1. Make sure you can run code --help from the command line and you get
    help.

    • if you do not see help, please follow these steps:

      • Mac: Select Shell Command: Install ‘Code’ command in path from the Command
        Palette.

        • Command Palette is what pops up when you press shift + + P while inside VS
          Code. (shift + ctrl + P in Windows)
      • Windows: Make sure you selected Add to PATH during the
        installation.
      • Linux: Make sure you installed Code via our new .deb or
        .rpm packages.
  2. From the command line, run git config --global core.editor "code --wait"

Now you can run git config --global -e and use VS Code as editor for configuring Git.
enter image description here
Add the following to enable support for using VS Code as diff tool:

[diff]
    tool = default-difftool
[difftool "default-difftool"]
    cmd = code --wait --diff $LOCAL $REMOTE

This leverages the new --diff option you can pass to VS Code to
compare two files side by side.

To summarize, here are some examples of where you can use Git with VS
Code:

  • git rebase HEAD~3 -i allows to interactive rebase using VS Code
  • git commit allows to use VS Code for the commit message
  • git add -p followed by e for interactive add
  • git difftool <commit>^ <commit> allows to use VS Code as diff editor for changes

Leave a Comment