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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github