The default editor used by Git, is the default editor setup for your user in your Bash session. Most often, Vim is the default editor. While I’m a big fan of Vim, it does take some time to master.
I've been using Vim for about 2 years now, mostly because I can't figure out how to exit it.
— I Am Devloper (@iamdevloper) February 17, 2014
Nano as an Alternative to Vim
In my experience, many users find Nano easier to use. You can tell your system to use Nano as your default editor when writing Git commit messages by typing
git config --global core.editor "nano"
You’ll only need to run this line once. It adds a line to your ~/.gitconfig
file, so Git uses Nano for all editing.
Other Alternatives
You can set Git to use any editor on your system, including graphical interface editors like Visual Studio Code. I personally prefer not to do this because I like my Git commit message editor in the window where I’m typing my Git commands.
Visual Studio Code
We first must make a modification so we can run Visual Studio Code from the command line.
- Run Visual Studio Code
- In the menu click
View
>Command Palette
- In the box that pops up, type
shell command
- Choose `Shell Command: Install ‘code’ command in PATH
Now when you type code
on the command line, Visual Studio Code will run.
Now that we can run Visual Studio Code from the command line with code
, we can set it as the editor for Git.
git config --global core.editor "code --wait"
MacVim
git config --global core.editor "mvim -f"
Atom
git config --global core.editor "atom --wait"
Sublime Text Editor
git config --global core.editor "subl -n -w"
I Don’t Need Any Editor
At this point you may be saying, “I don’t need any editor. I use the - m
parameter with git commit
to enter my commit message as part of the command. e.g.
git commit -m 'Fix Spacebar causing CPU to overheat'
Please Don’t Do This
Please do not use the one line version of commit messages (made popular by the parameter -m
). Well crafted commit messages are invaluable. For more information on writing valuable commit messages, see How to Write a Git Commit Message.
Leave a Reply