commit
coding
editor
git

How do I make git use the editor of my choice for editing commit messages?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Git chooses an editor for commit messages, rebases, merges, and other interactive operations based on configuration and environment variables. The most direct way to change it is to set core.editor to the command you want Git to run.

The practical detail that trips people up is that some GUI editors must be launched with a “wait until closed” flag. If you forget that, Git may think editing finished immediately.

Set the Editor Globally

To choose one editor for your user account across all repositories:

bash
git config --global core.editor "nano"

Or for Visual Studio Code:

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

For Vim:

bash
git config --global core.editor "vim"

This writes the setting into your global Git config, usually under ~/.gitconfig.

Set the Editor for One Repository Only

If you want a repository-specific override, run the same command without --global inside that repository.

bash
git config core.editor "nvim"

That setting goes into the local .git/config file and affects only that repository.

Verify What Git Is Using

To inspect the configured editor value:

bash
git config --show-origin --get core.editor

The --show-origin flag is useful because it tells you where the value came from. That helps when a local config, global config, or included config file is overriding what you expected.

Environment Variables Can Override the Config

Git also honors environment variables, especially GIT_EDITOR. In many shells, this can override core.editor.

bash
export GIT_EDITOR="code --wait"

There is also a broader editor environment convention through VISUAL and EDITOR, which some tools use. Git can fall back through those if core.editor is not set.

This means the effective editor may come from more than one place. When behavior looks inconsistent, check both Git config and the shell environment.

GUI Editors Usually Need a Wait Flag

Terminal editors such as vim or nano naturally block until you exit. GUI editors often do not, so Git needs help.

Examples:

bash
git config --global core.editor "code --wait"
git config --global core.editor "subl -n -w"

Without the wait flag, Git may open the editor and immediately continue, which often produces an empty commit message or an aborted commit.

One-Off Override for a Single Command

If you want to change the editor for just one operation, prefix the command with GIT_EDITOR.

bash
GIT_EDITOR="nano" git commit

That is useful in scripts, remote shells, or debugging situations where you do not want to change your persistent Git configuration.

Common Pitfalls

  • Setting core.editor to a GUI editor command without the required wait flag.
  • Forgetting that a repository-local config can override the global editor setting.
  • Debugging the wrong config file because the real value came from GIT_EDITOR or another environment variable.
  • Using a command that works in an interactive shell but is not on PATH when Git launches it.
  • Assuming this setting affects only commits when it also affects other Git edit flows such as rebases and merges.

On Windows, quoting also matters more often because editor paths may contain spaces. If Git cannot launch the editor, test the exact command string outside Git first.

Summary

  • Use git config --global core.editor "..." to set your preferred editor for Git.
  • Use repository-local config when you want a per-project override.
  • GUI editors usually need a wait flag such as --wait or -w.
  • Check GIT_EDITOR, VISUAL, and EDITOR if behavior is unexpected.
  • 'git config --show-origin --get core.editor is the fastest way to see where the current setting comes from.'

Course illustration
Course illustration

All Rights Reserved.