Choose the editor Git uses for commit messages

Configure core.editor with the right wait option, inspect editor precedence, and distinguish commit-message editing from the interactive rebase sequence editor.

Best practices
Illustration of Git branches and version history

Set core.editor to the command Git should run for commit-message editing. For Visual Studio Code:

git config --global core.editor 'code --wait'

The editor command must stay running until editing is complete. Without a suitable wait option, a graphical launcher can return before you save, leaving Git to continue with an unchanged or empty message.

Common choices

Choose one configuration:

git config --global core.editor 'code --wait'
git config --global core.editor 'subl -w'
git config --global core.editor nano
git config --global core.editor vim

On Windows, you can configure an installed editor such as Notepad, but confirm that the particular launcher waits as required. Quote executable paths containing spaces appropriately for the shell and Git command string.

For only the current repository, omit --global:

git config core.editor 'code --wait'

Check which editor wins

The normal editor precedence is:

  1. GIT_EDITOR environment variable.
  2. core.editor configuration.
  3. VISUAL environment variable.
  4. EDITOR environment variable.
  5. Git's compiled-in default.

Inspect the selected command with:

git var GIT_EDITOR

Setting EDITOR can also affect other command-line programs, but it does not override an explicit Git editor setting or GIT_EDITOR.

Interactive rebase has another selector

An interactive rebase's todo list can use GIT_SEQUENCE_EDITOR or sequence.editor. Those take precedence over the normal editor for that task. Editing an individual commit message during a rebase uses the message editor instead.

Git commonly opens the message editor for git commit without -m, amend operations, and merge commits that require editing. A supplied message or options such as --no-edit can avoid it when appropriate.

FAQ

Why does Git say code was not found?

Confirm code --version works in the shell where Git runs. On macOS, VS Code provides a Command Palette action to install the code shell command in PATH. Other platforms typically use installer or package-manager PATH setup; the macOS palette action is not a universal instruction for every system.

How do I leave Vim?

Press Escape, type :wq, and press Enter to save and exit. :cq exits with a failure status, which tells Git that editing failed and stops the operation. Simply quitting without changes is not always a reliable way to cancel a prefilled commit message.

Can I provide a message directly?

Yes: git commit -m "Describe the change". Use an editor when a longer explanation is easier to review there.

See git-var, git-config, and VS Code's command-line interface.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting