How to Change the Editor Git Uses for Commit Messages
Running git config --global core.editor vim changes the editor that git commit opens. If you committed without -m and an unfamiliar editor opened that you couldn't get out of, this is how you switch to one you know. The editor Git currently uses can be checked with git var GIT_EDITOR. I ran the git commands in a test environment and include the output from before and after the setting was changed, as it appeared.
The test environment was Ubuntu 24.04, Git 2.43.0, nano 7.2, and Vim 9.1. For the author's name and email, I used example values (Neko <neko@example.com>), and for the repository location, an example path (/path/to/neko-app). I ran nano and vim inside a terminal and operated them by sending keys from a program. I did not test GUI editors that are not installed in this environment, such as VS Code, or behavior on Windows or macOS.
Before the setting, nano opened on Ubuntu
In a repository named neko-app, I started with no editor-related settings or environment variables. git config --get core.editor printed nothing and ended with exit code 1. There were also no GIT_EDITOR, VISUAL, or EDITOR environment variables.
$ git config --get core.editor; echo "終了コード: $?"
終了コード: 1
$ env | grep -E "^(GIT_EDITOR|VISUAL|EDITOR)=" ; echo "終了コード: $?"
終了コード: 1
The editor Git uses can be displayed with git var GIT_EDITOR. In this state it printed editor. Following editor with readlink -f showed that, in the test environment, it pointed to nano.
$ git var GIT_EDITOR
editor
$ readlink -f /usr/bin/editor
/usr/bin/nano
The official reference for git var says that when nothing is configured, the default editor is decided when Git is built, and is usually vi. In the Ubuntu Git I tested, it was editor.
In this state, I added style.css and ran git commit without -m, and nano opened. The screen below is just before saving: the subject is on the first line, the body follows after one blank line, and the editor is about to be closed.

In nano, Ctrl+O and Enter save, and Ctrl+X exits. After exiting, the commit had been made.
$ git log -1
commit b41435a6c82ecaefc2712cc1b05f7cb78f66a5af
Author: Neko <neko@example.com>
Date: Thu Nov 12 09:10:00 2026 +0900
文字の色を決める
本文の文字を濃い灰色にした。
Change the editor with core.editor
To set the editor used in every repository, use git config --global core.editor. Here I set it to vim. The value you set can be read back with --get. The output of git var GIT_EDITOR also changed from editor to vim.
$ git config --global core.editor vim
$ git config --global --get core.editor
vim
$ git var GIT_EDITOR
vim
I added one line to style.css and ran git commit without -m again. This time vim opened.

In vim, press i to start typing. When you finish, press Esc, then enter :wq and Enter to save and exit. The history after exiting:
$ git log -1
commit b9764ff03ef60f5c3b5e4e698d383382661f0981
Author: Neko <neko@example.com>
Date: Thu Nov 12 09:20:00 2026 +0900
見出しの色を決める
見出しを濃い水色にした。
With either editor, git commit waits until the editor closes, and then commits with the saved content.
For VS Code and similar editors, set them with an option that makes Git wait
If you use VS Code, don't set just code. Add --wait and set git config --global core.editor "code --wait". This form is listed in the per-editor core.editor settings in the appendix of Pro Git. The same list includes other editors, such as "nano -w" for nano and "atom --wait" for Atom. The VS Code command-line documentation describes --wait as an option that returns only after the file is closed.
git commit waits for the editor command to finish and then uses the file's contents at that point as the message. So if you configure a command that finishes as soon as the window opens, the editor is treated as done before you have written anything. To check this, I temporarily set a shell script that exits immediately without doing anything (../returns-at-once.sh is a file placed one level above the repository).
$ printf '#!/bin/sh\n# ファイルを開いたらすぐ終わる(待たない)エディターの代わり\nexit 0\n' > ../returns-at-once.sh && chmod +x ../returns-at-once.sh
$ git config --global core.editor ../returns-at-once.sh
$ git commit --allow-empty; echo "終了コード: $?"
Aborting commit due to empty commit message.
終了コード: 1
With the message still empty, the commit was aborted. git log --oneline shows no new commit.
$ git log --oneline
b9764ff 見出しの色を決める
b41435a 文字の色を決める
b3cf454 トップページを作る
If the configured command cannot be found, Git reports that it cannot start the editor. This is the output when I set code in the test environment, where VS Code is not installed.
$ git config --global core.editor code
$ git commit --allow-empty; echo "終了コード: $?"
error: cannot run code: No such file or directory
error: unable to start editor 'code'
Please supply the message using either -m or -F option.
終了コード: 1
Environment variables can take precedence
The official reference for git var says Git chooses its editor in this order: the environment variable GIT_EDITOR, then the core.editor setting, then the environment variable VISUAL, then EDITOR. I set core.editor back to vim and then ran git var GIT_EDITOR with each environment variable set in turn.
$ git config --global core.editor vim
$ EDITOR=nano git var GIT_EDITOR
vim
$ VISUAL=nano git var GIT_EDITOR
vim
$ GIT_EDITOR=nano git var GIT_EDITOR
nano
core.editor took precedence over EDITOR and VISUAL, and GIT_EDITOR took precedence over core.editor. After I removed core.editor, EDITOR was used, and when both VISUAL and EDITOR were set, VISUAL was used.
$ git config --global --unset core.editor
$ EDITOR=nano git var GIT_EDITOR
nano
$ VISUAL="vim" EDITOR=nano git var GIT_EDITOR
vim
If the editor does not change after you set core.editor, check whether GIT_EDITOR is set in a shell configuration file or similar. The output of git var GIT_EDITOR shows the editor that is actually used.
Change it per repository
If you run git config core.editor inside a repository without --global, the setting applies only to that repository. I set the global core.editor back to vim, then set only neko-app to nano -w.
$ git config --global core.editor vim
$ git config core.editor "nano -w"
$ git var GIT_EDITOR
nano -w
$ git config --show-scope --get-all core.editor
global vim
local nano -w
With --show-scope, you can see where each value is set: global applies to all repositories, and local applies to this repository. When both exist, the repository setting, nano -w, was used. Running the command outside the repository returns vim. Here I moved into the parent directory inside a subshell with parentheses, so the shell stays in the repository after the command.
$ (cd .. && git var GIT_EDITOR)
vim
When I removed the repository setting with --unset, the repository also went back to vim.
$ git config --unset core.editor
$ git var GIT_EDITOR
vim
Remove the setting to go back
The global setting can also be removed with --global --unset. After removing it, the editor returned to editor (nano in the test environment), as it was at the start.
$ git config --global --unset core.editor
$ git config --global --get core.editor; echo "終了コード: $?"
終了コード: 1
$ git var GIT_EDITOR
editor
According to the official reference for core.editor in git-config, this setting is used not only by commit but also by other commands that have you write a message in an editor, such as tag.



