How Do I Make Git Use the Editor of My Choice for Editing Commit Messages?

Better Stack Team
Updated on June 24, 2024

To make Git use the editor of your choice for editing commit messages, you can configure the core.editor setting in your Git configuration. Here's how you can do it:

Using Command Line:

Open your terminal and run the following command, replacing <editor> with the command-line name of the editor you want to use (e.g., vim, nano, emacs, code, etc.):

 
git config --global core.editor <editor>

For example, to set Visual Studio Code as your default editor, you can run:

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

The --wait option ensures that Git waits for Visual Studio Code to close before proceeding.

Using a Specific Editor with Custom Arguments:

If your editor requires specific arguments or flags, you can include them within the quotes. For example:

 
git config --global core.editor "vim -c 'set tw=72' -c 'set colorcolumn=73' +startinsert"

This command configures Vim with specific settings.

Verify Configuration:

To verify that the editor has been set correctly, you can use the following command:

 
git config --global core.editor

This command will display the currently configured editor.

Note:

  • Ensure that the editor you specify is installed on your system and is accessible via the command line.
  • You can also set the editor per repository by omitting the -global flag when running git config.
  • If you omit the -global flag, the configuration will apply only to the current repository.
  • Configuring the default editor is a one-time setup, and Git will use the specified editor for all future commit messages.
Got an article suggestion? Let us know
Explore more
Git
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.