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:
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.
- 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. 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 Codegit commit
allows to use VS Code for the commit messagegit add -p
followed bye
for interactive addgit difftool <commit>^ <commit>
allows to use VS Code as diff editor for changes
git config --global core.editor "code --wait"
or
git config --global core.editor "code -w"
verify with:
git config --global -e
Your configuration will open in Visual Studio Code.
For what I understand, VSCode is not in AppData anymore.
So Set the default git editor by executing that command in a command prompt window:
git config --global core.editor "'C:\Program Files (x86)\Microsoft VS Code\code.exe' -w"
The parameter -w
, --wait
is to wait for window to be closed before returning. Visual Studio Code is base on Atom Editor. if you also have atom installed execute the command atom --help
. You will see the last argument in the help is wait.
Next time you do a git rebase -i HEAD~3
it will popup Visual Studio Code. Once VSCode is close then Git will take back the lead.
Note: My current version of VSCode is 0.9.2
I hope that help.