How can I use Visual Studio Code as the default editor for Git?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Using Visual Studio Code as your default Git editor improves consistency across commit, merge, and rebase workflows. The key requirement is launching VS Code in a mode where Git waits until editing is finished. Once configured correctly, commit message editing and interactive operations become much smoother.
Set core.editor to VS Code
The standard configuration is code --wait. The --wait flag is essential because it blocks until the editor window is closed.
Without --wait, Git may continue immediately and treat the message as empty.
For one repository only:
Configure Rebase and Sequence Editing
Interactive rebase uses a sequence editor. You can point that explicitly to VS Code as well.
Now commands such as git rebase -i HEAD~5 open the todo file in VS Code with expected wait behavior.
Platform-Specific Notes
On most systems, the code command is available after installing the VS Code shell command.
On macOS, run the command palette action named shell command install code in path. On Windows, ensure VS Code installation adds the command to PATH or reference full executable path in Git config.
Example with explicit path if needed:
Quoted paths are important when directories contain spaces.
Test the Configuration Quickly
Use a small temporary repository and run a commit without -m.
Git should open VS Code for the commit message and return only after the editor is closed.
Optional Quality-of-Life Improvements
A few related settings improve overall authoring flow:
commit.verboseto include diff context in message buffer.pull.rebaseif your team uses rebase-first integration.- template commit messages with
commit.template.
If commit templates are used, VS Code highlights them nicely and encourages consistent message quality.
VS Code and Merge Tools
Default editor and merge tool are separate Git settings. If you also want VS Code for merge conflict resolution:
This allows conflict files to open in VS Code during merge tool flows.
Troubleshooting
If Git says code command not found, PATH is not configured for the VS Code CLI command. Install or re-enable shell command integration, then open a new terminal session.
If VS Code opens but Git does not wait, verify the exact value of core.editor and ensure --wait is present.
If another tool still opens for rebase, check sequence.editor and environment variables such as GIT_EDITOR that can override config values.
Clear conflicting environment settings in shell profiles if needed.
Common Pitfalls
A common pitfall is setting only core.editor and forgetting sequence.editor, then expecting rebase todo files to open in the same editor.
Another issue is storing an unquoted Windows path in Git config. Spaces break command parsing and cause editor launch errors.
Developers also test configuration in one shell session and assume all terminals share the same PATH. Restart terminals after CLI integration changes.
Finally, team scripts may set GIT_EDITOR temporarily and override user config. Check automation wrappers when behavior seems inconsistent.
Summary
- Set Git editor to
code --waitso Git blocks until editing is complete. - Configure
sequence.editorfor interactive rebase workflows. - Quote executable paths when they include spaces.
- Validate setup with a commit flow that opens editor input.
- Check PATH and override variables when troubleshooting editor launch issues.

