How do I globally configure git to use a particular editor (e.g. vim
) for commit messages?
Pick one:
Set core.editor
in your Git config:
git config --global core.editor "vim"
Set the GIT_EDITOR
environment variable:
export GIT_EDITOR=vim
Set the standardized VISUAL
and EDITOR
environment variables*:
export VISUAL=vim
export EDITOR="$VISUAL"
NOTE: Setting both is not necessarily needed, but some programs may not use the more-correct VISUAL
. See VISUAL
vs. EDITOR
.
Some editors require a --wait
flag, or they will open a blank page. For example:
Sublime Text (if correctly set up; or use the full path to the executable in place of subl
):
export VISUAL="subl --wait"
VS Code (after adding the shell command):
export VISUAL="code --wait"
Answered 2023-09-20 20:18:32
git config --global
would write to your personal (per-user) git configuration file. On Unices it is ~/.gitconfig
. So this would configure it for all your repositories. - anyone git commit --amend
- anyone -w
is not necessary; -w {scriptout}
saves all characters you type when editing to replay later. Perhaps you are confusing it with -f
, which is necessary when calling the GUI version of Vim. That is, if you use mvim
, then the editor you specify should be mvim -f
rather than mvim
. - anyone Run:
git config --global core.editor "vim"
From man git-commit
:
ENVIRONMENT AND CONFIGURATION VARIABLES
The editor used to edit the commit log message will be chosen from the
GIT_EDITOR
environment variable, thecore.editor
configuration variable, theVISUAL
environment variable, or theEDITOR
environment variable (in that order).
Answered 2023-09-20 20:18:32
VISUAL
or EDITOR
, but they certainly don't use GIT_EDITOR
or core.editor
. - anyone On Ubuntu and also Debian (thanks @MichielB) changing the default editor is also possible by running:
sudo update-alternatives --config editor
Which will prompt the following:
There are 4 choices for the alternative editor (providing /usr/bin/editor).
Selection Path Priority Status
------------------------------------------------------------
0 /bin/nano 40 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
* 3 /usr/bin/vim.basic 30 manual mode
4 /usr/bin/vim.tiny 10 manual mode
Press enter to keep the current choice[*], or type selection number:
Answered 2023-09-20 20:18:32
alternatives
system is a much easier way to manage defaults for the supported program types. For reference: debian-administration.org/article/91/… - anyone GIT_EDITOR
and EDITOR
not work --ubuntu - anyone update-alternatives
will show any editors that have been installed. Koen just doesn't have Emacs installed. - anyone In windows 7, while adding the "Sublime" editor it was still giving me an error:
Aborting commit due to empty commit message.
Sublime was not able to keep the focus.
To fix this I opened the .gitconfig file in c:/users/username/ folder and added the following line with --wait option outside the single quotes.
[core]
editor = 'F:/Program Files/Sublime Text 2/sublime_text.exe' --wait
Hope its helpful to somebody facing similar issue with Sublime.
Answered 2023-09-20 20:18:32
git config --global core.editor "'C:/Program Files/Sublime Text 3/subl.exe' --wait"
- anyone C:\Users\YOUR_USERNAME\.gitconfig
For 64 bit Notepad++ use:
[core]
editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar
For 32 bit Notepad++ use:
[core]
editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar
git commit
and press Enter
. It will pop open Notepad++.Answered 2023-09-20 20:18:32
-multiInst
as a parameter to notepad++ and possibly -notabbar
. Do this if git doesn't seem to know when you've finished editing the file and either waits forever or not at all. - anyone >git config --global core.editor '"C:/Program Files (x86)/Notepad++/notepad++.exe"'
- anyone editor = 'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar
- that is, params outside the delimiting single quotes - anyone To make Visual Studio Code (vscode
) the default git editor:
git config --global core.editor "code --wait"
Answered 2023-09-20 20:18:32
And if you are working with designers using the command line then Pico, and dont know short cuts ;)
git config --global core.editor "pico"
Or
export VISUAL=pico
export EDITOR=pico
Answered 2023-09-20 20:18:32
git config --global core.editor "atom --wait"
Atom needs to be configured to run from the command line for the above to work:
OS X: install shell commands from Atom: menu bar > Atom > Install Shell Commands
Windows: no action required - atom is configured to run from the command line by default
Answered 2023-09-20 20:18:32
git config --global core.editor "code --wait"
- anyone Run this command:
$ git config --global core.editor "/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
Or just:
$ git config --global core.editor "subl -w"
Answered 2023-09-20 20:18:32
-w
parameter. Eg. $ git config --global core.editor "code -w"
. Neat stuff - anyone To make vim the default editor for git on ubuntu 20:04 run the following command:
git config --global core.editor vim
Answered 2023-09-20 20:18:32
This provides an answer for people who arrive at this Question that may want to link an editor other than vim.
The linked resource, by Github,is likely to be kept up to date, when editors are updated, even if answers on SO (including this one) are not.
Associating Text Editors with git
Github's post shows exactly what to type in to your command line for various editors, including the options/flags specific to each editor for it to work best with git.
Notepad++:
git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Sublime Text:
git config --global core.editor "'c:/Program Files/sublime text 3/subl.exe' -w"
Atom:
git config --global core.editor "atom --wait"
The commands above assume your editor has been installed in the default directory for a windows machine.
The commands basically add the text between double-quotes to .gitconfig
in your home directory.
On a windows machine home is likely to be C:\Users\your-user-name
, where your-user-name is your login name.
From the command line, you can reach this directory by typing in cd ~
.
for example, a command above would be add the following line under the [core]
section like so:
[core]
editor = 'C:/Program Files/sublime text 3/subl.exe' -w
If you have a different editor, just replace with the path to your editor, using either method above. (and hope no flags are needed for optimal usage.)
Answered 2023-09-20 20:18:32
git config --global core.editor notepad.exe
Hit Ctrl+S to save your commit message. To discard, just close the notepad window without saving.
In case you hit the shortcut for save, then decide to abort, go to File->Save as, and in the dialog that opens, change "Save as type" to "All files (*.*)". You will see a file named "COMMIT_EDITMSG". Delete it, and close notepad window.
Edit: Alternatively, and more easily, delete all the contents from the open notepad window and hit save. (thanks mwfearnley for the comment!)
I think for small write-ups such as commit messages notepad serves best, because it is simple, is there with windows, opens up in no time. Even your sublime may take a second or two to get fired up when you have a load of plugins and stuff.
Answered 2023-09-20 20:18:32
core.editor = 'notepad' .git/COMMIT_EDITMSG --wait
so it opens and saves the default edit message and you dont need "save as" - anyone For emacs users
.emacs
:
(server-start)
shellrc
:
export EDITOR=emacsclient
Answered 2023-09-20 20:18:32
git config --global core.editor "emacs -nw"
- anyone git config --global core.editor "emacs -nw -q"
, where the -q
skips initialization files. - anyone You could either:
git config --global core.editor "vim"
Or, in your .gitconfig
:
[core]
editor = vim
Answered 2023-09-20 20:18:32
To follow these instructions in Windows make sure you have installed Git for Windows. In Windows, I like to use Git Bash so that it feels more like Linux.
First, we want to create a special Sublime Text project so that we can specify special project settings we want set whenever Git calls the editor, to make things easier when editing in Git. For example, I normally set my ruler to 120 chars in most projects, but for Git commit messages I want it to be 72 characters so that it fits nicely in a terminal when you call git log
or git lg
.
Open Sublime Text and go to menu "File" → "New Window" to create a new anonymous project. Go to menu "Project" → "Save Project As..." and choose a place to save it. In Linux I saved it in my Linux home directory with the file name .gitconfig.sublime-project
. Its path is therefore: ~/.gitconfig.sublime-project
. In Windows also save it in your home directory, for example: C:\Users\MY_USER_NAME\.gitconfig.sublime-project
Now go to menu "Project" → "Edit Project" to edit the project settings. Paste the following and save the settings. Make any further edits for your project settings if desired.
{
// For folder settings help see here: https://www.sublimetext.com/docs/3/projects.html
"folders":
[
],
"settings":
{
// Disables horizontal scrolling if enabled.
// May be set to true, false, or "auto", where it will be disabled for
// source code, and otherwise enabled.
"word_wrap": false,
// Set to a value other than 0 to force wrapping at that column rather than the
// window width
"wrap_width": 0,
// Columns in which to display vertical rulers
"rulers": [72, 50], //72 is recommended by git for commit message content, and 50 for commit titles
// The number of spaces a tab is considered equal to
"tab_size": 4,
// Set to true to insert spaces when tab is pressed
"translate_tabs_to_spaces": true,
},
"build_systems":
[
]
}
Now we need to set the editor to be used by Git, by editing the .gitconfig
file.
Your user copy of this will be located in ~/.gitconfig
. Open this file and add the following lines. Be sure to use the proper path name to the Git project you just created above! I'm using ~/.gitconfig.sublime-project
.
[core]
editor = subl --project ~/.gitconfig.sublime-project --wait
The --wait
is important, as it forces Git to wait until you close the file before it continues on. The --project
line is important to tell Sublime Text which project you want opened whenever Git opens Sublime Text.
Per @digitaldreamer's answer above (https://stackoverflow.com/a/2596835/4561887), "subl
can be replaced by the full path of the executable but [the alias subl
] is usually available when [Sublime is] correctly installed."
For Windows, first read the Linux instructions for background information. Now we will do something almost identical.
(OPTIONAL, but highly recommended: create a subl
alias for use in Git Bash):
Open up a text editor (for example, Notepad, Notepad++, Sublime Text, Geany, etc.), and create a file called .bash_profile
in your home directory, if it doesn't already exist. You can also use .bashrc
, which is probably more-recommended. Its path will therefore be: C:\Users\MY_USER_NAME\.bash_profile
or C:\Users\MY_USER_NAME\.bashrc
. Save the following into it:
# (copy and paste this into the bottom of your ~/.bashrc (recommended) or
# ~/.bash_profile file)
alias subl="/c/Program\ Files/Sublime\ Text/subl.exe"
This creates a Git Bash alias called subl
that we can now use in Git Bash for Windows, to easily open Sublime Text. This step isn't required, but it's useful for general Git Bash use. Close and re-open your Git Bash terminals. Now, you can call subl .
, for instance, in Git Bash to open up a new Sublime Text project in your current directory.
(MANDATORY):
Edit the .gitconfig
file found in your home directory: C:\Users\MY_USER_NAME\.gitconfig
, by adding the following to it. Notice the subtle changes from the Linux instructions above:
[core]
editor = 'C:/Program Files/Sublime Text/subl.exe' --project ~/.gitconfig.sublime-project --wait
/
NOT \
to separate folders in the path name! (Thanks VonC for helping me see this).subl
alias we made for Git Bash above doesn't work in the .gitconfig
settings above, so you can't use it like we did in the Linux example. Instead, you must specify the whole path as shown above.~
symbol, however, does still work here to get to your Windows home directory.This gives you syntax highlighting for git commit
messages, as well as access to other Git commands such as git blame
(which I use frequently in Sublime Text) or git commit
(which I don't use in Sublime Text since I'd prefer the command-line for general Git flow, as I've mentioned in my comments below this answer).
To install a package: First, ensure “Package Control” is installed. Next, press Ctrl + Shift + P (same as Tools → Command Palette) and type all or part of “Package Control: Install Package”, then press Enter. In the search box that comes up, search for the package "Git" and hit Enter on it, or click on it, to automatically install it.
Once installed, Ctrl + Shift + P then searching for "git" will bring up Git commands you can use internally inside Sublime Text now, such as git blame
.
Now when you call git commit
, for instance, as normal from the command-line, Sublime Text will open up into the .gitconfig.sublime-project
we created above, with that project's settings! As you type a paragraph you'll notice it extends past the ruler we set since soft word-wrap is off. To force hard wrap via auto-inserted hard-returns at the end of each line, put your cursor on the long line you want auto-wrapped and press Alt + Q. It will now hard-wrap/hard-fold at 72 characters, which is what we set in the project settings' "rulers" parameter above.
Now, save your commit message with Ctrl + S, and exit (to complete your git commit
) with Ctrl + Shift + W.
Done!
Answered 2023-09-20 20:18:32
Git Commit
syntax type. You can skip the custom "sublime-text project" step now. - anyone sublime
with git
and also use trim_trailing_white_space_on_save
you want to add an alias for patch adding because removing trailing white space breaks patch edits where it's very much meaningful. This can be achieved with something like this: git config --global alias.patch "-c core.editor=vim add --patch"
- anyone there is a list of commad that you can use but for vs code use this
git config --global core.editor "code --wait"
this is the link for all editor :https://git-scm.com/book/en/v2/Appendix-C%3A-Git-Commands-Setup-and-Config
Answered 2023-09-20 20:18:32
Set core.editor in your Git config:
git config --global core.editor "nano"
Set the GIT_EDITOR environment variable:
export GIT_EDITOR=nano
Answered 2023-09-20 20:18:32
Like all the other GUI applications, you have to launch mvim with the wait flag.
git config --global core.editor "mvim --remote-wait"
Answered 2023-09-20 20:18:32
--remote-wait-silent
to avoid ugly error message :) - anyone For Mac OS X, using TextEdit or the natural environmental editor for text:
git config --global core.editor "open -W -n"
Answered 2023-09-20 20:18:32
For Windows users who want to use neovim with the Windows Subsystem for Linux:
git config core.editor "C:/Windows/system32/bash.exe --login -c 'nvim .git/COMMIT_EDITMSG'"
This is not a fool-proof solution as it doesn't handle interactive rebasing (for example). Improvements very welcome!
Answered 2023-09-20 20:18:32
git config --global core.editor "nvim"
Done 🤘
Answered 2023-09-20 20:18:32
Just because I came here looking for a one-time solution (in my case, I usually use vim
but this one time I wanted to use VS Code) for a single command and others might want to know as well:
GIT_EDITOR='code -w' git rebase -i …
Here's my git
/hub
version just for context:
git version 2.24.2 (Apple Git-127)
hub version 2.14.1
Answered 2023-09-20 20:18:32
git config --global core.editor "open -n -W -a TextWrangler"
Also, make sure your "TextWrangler > Preferences > Application > When TextWrangler becomes active:" setting is set to "Do nothing"
This works for me on OS X 10.11.4 with TextWrangler 5.0.2 from the Mac app store.
Explanation:
The -n means open in a new instance.
The -W means to wait until the application exits before using the contents of the edited file as the commit message.
The -a TextWrangler means use the TextWrangler application to open the file.
See man open
in your Mac Terminal app for more details.
Answered 2023-09-20 20:18:32
git config --global core.editor "edit -w"
. This will open the commit message in the current instance and as soon as you close only this commit message document, the commit will continue. - anyone When using git-review
I had to modify sequence.editor
value to be able to do interactive rebase (git rebase -i -p
):
git config --global sequence.editor "gvim" # or whatever your prefer
gvim
require: apt install vim-gtk
Answered 2023-09-20 20:18:32
On macOS Big Sur (11.0) beta for TextMate: none of the environment variable options worked. (Set all three: GIT_EDITOR, VISUAL, and EDITOR.)
Finally set the global core.editor in git, and that worked:
git config --global core.editor "~/bin/mate -w"
Answered 2023-09-20 20:18:32
For Windows, Neovim:
# .gitconfig
[core]
editor='C:/tools/neovim/Neovim/bin/nvim-qt.exe'
Answered 2023-09-20 20:18:32
git config --global core.editor "code --wait"
To revert the changes made to the Git configuration and restore the default editor, you can use the following commands:
git config --global --unset core.editor
Answered 2023-09-20 20:18:32
Just try EDITOR=vim git commit
.
Or you can set your EDITOR to vim by export EDITOR=vim
in your bashrc.
Answered 2023-09-20 20:18:32
This opens Textmate editor in when you want to edit your commits. Requires textmate command line tools to be installed.
git config --global core.editor "mate -w"
Answered 2023-09-20 20:18:32
git config --global core.editor "/usr/local/bin/mate -w"
- anyone Create a file called 'k.sh', add the following text and place in your home directory (~):
winpty "C:\Program Files (x86)\Kinesics Text Editor\x64\k.exe" $1
At the git prompt type:
git config --global core.editor ~/k.sh
Answered 2023-09-20 20:18:32