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:
Or for Visual Studio Code:
For 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.
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:
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.
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:
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.
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.editorto 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_EDITORor another environment variable. - Using a command that works in an interactive shell but is not on
PATHwhen 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
--waitor-w. - Check
GIT_EDITOR,VISUAL, andEDITORif behavior is unexpected. - '
git config --show-origin --get core.editoris the fastest way to see where the current setting comes from.'

