How to Set VS Code as Default Git Editor
This guide provides a straightforward, step-by-step walkthrough on how to configure Visual Studio Code (VS Code) as your default text editor for Git commands. You will learn the exact terminal commands needed for global configuration, how to handle system-specific requirements, and how to verify that the setup was successful.
Step 1: Run the Git Configuration Command
To set VS Code as your default Git editor globally, open your terminal (macOS/Linux) or Command Prompt/PowerShell (Windows) and run the following command:
git config --global core.editor "code --wait"The --wait flag is essential. It instructs Git to pause
the terminal session until you close the newly opened VS Code tab or
window, ensuring Git captures your saved text before proceeding.
Step 2: Ensure the ‘code’ Command is in Your PATH
For the configuration to work, your operating system must recognize
the code command.
On macOS:
- Open Visual Studio Code.
- Press
Cmd + Shift + Pto open the Command Palette. - Type
Shell Commandand select Shell Command: Install ‘code’ command in PATH. - Restart your terminal.
On Windows and Linux:
The installer typically adds VS Code to your system PATH
automatically during installation. If the code command is
not recognized, reinstall VS Code and ensure the “Add to PATH” option is
checked.
Step 3: Verify the Configuration
To confirm that Git is now using VS Code as its default editor, run the following verification command:
git config --global core.editorThe output in your terminal should be:
code --wait
Alternatively, you can test the setup by initiating a Git action that
requires an editor, such as making a commit without the -m
flag:
git commitVS Code will automatically launch a temporary text file. Type your
commit message, save the file (Ctrl + S or
Cmd + S), and close the tab to complete the commit
process.
Alternative Method: Editing .gitconfig Directly
If you prefer to edit your global Git configuration file manually,
open your .gitconfig file (located in your user home
directory) and add or modify the [core] section as
follows:
[core]
editor = code --wait