Visual Studio Code
Git
Default Editor
Code Editor
Version Control

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.

bash
1# global setting for all repositories
2git config --global core.editor "code --wait"
3
4# verify
5git config --global --get core.editor

Without --wait, Git may continue immediately and treat the message as empty.

For one repository only:

bash
git config core.editor "code --wait"

Configure Rebase and Sequence Editing

Interactive rebase uses a sequence editor. You can point that explicitly to VS Code as well.

bash
git config --global sequence.editor "code --wait"

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:

bash
git config --global core.editor ""C:/Program Files/Microsoft VS Code/Code.exe" --wait"

Quoted paths are important when directories contain spaces.

Test the Configuration Quickly

Use a small temporary repository and run a commit without -m.

bash
1mkdir git-editor-test && cd git-editor-test
2git init
3echo "demo" > README.md
4git add README.md
5git commit

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.verbose to include diff context in message buffer.
  • pull.rebase if your team uses rebase-first integration.
  • template commit messages with commit.template.
bash
git config --global commit.verbose true
git config --global commit.template ~/.gitmessage.txt

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:

bash
git config --global merge.tool vscode
git config --global mergetool.vscode.cmd "code --wait $MERGED"

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.

bash
env | grep GIT_EDITOR

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 --wait so Git blocks until editing is complete.
  • Configure sequence.editor for 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.

Course illustration
Course illustration

All Rights Reserved.