Question

I'm trying out Git on Windows. I got to the point of trying "git commit" and I got this error:

Terminal is dumb but no VISUAL nor EDITOR defined. Please supply the message using either -m or -F option.

So I figured out I need to have an environment variable called EDITOR. No problem. I set it to point to Notepad. That worked, almost. The default commit message opens in Notepad. But Notepad doesn't support bare line feeds. I went out and got Notepad++, but I can't figure out how to get Notepad++ set up as the %EDITOR% in such a way that it works with Git as expected.

I'm not married to Notepad++. At this point I don't mind what editor I use. I just want to be able to type commit messages in an editor rather than the command line (with -m).

Those of you using Git on Windows: What tool do you use to edit your commit messages, and what did you have to do to make it work?

Was it helpful?

Solution

Update September 2015 (6 years later)

The last release of git-for-Windows (2.5.3) now includes:

By configuring git config core.editor notepad, users can now use notepad.exe as their default editor.
Configuring git config format.commitMessageColumns 72 will be picked up by the notepad wrapper and line-wrap the commit message after the user edits it.

See commit 69b301b by Johannes Schindelin (dscho).

And Git 2.16 (Q1 2018) will show a message to tell the user that it is waiting for the user to finish editing when spawning an editor, in case the editor opens to a hidden window or somewhere obscure and the user gets lost.

See commit abfb04d (07 Dec 2017), and commit a64f213 (29 Nov 2017) by Lars Schneider (larsxschneider).
Helped-by: Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 0c69a13, 19 Dec 2017)

launch_editor(): indicate that Git waits for user input

When a graphical GIT_EDITOR is spawned by a Git command that opens and waits for user input (e.g. "git rebase -i"), then the editor window might be obscured by other windows.
The user might be left staring at the original Git terminal window without even realizing that s/he needs to interact with another window before Git can proceed. To this user Git appears hanging.

Print a message that Git is waiting for editor input in the original terminal and get rid of it when the editor returns, if the terminal supports erasing the last line


Original answer

I just tested it with git version 1.6.2.msysgit.0.186.gf7512 and Notepad++5.3.1

I prefer to not have to set an EDITOR variable, so I tried:

git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\""
# or
git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\" %*"

That always gives:

C:\prog\git>git config --global --edit
"c:\Program Files\Notepad++\notepad++.exe" %*: c:\Program Files\Notepad++\notepad++.exe: command not found
error: There was a problem with the editor '"c:\Program Files\Notepad++\notepad++.exe" %*'.

If I define a npp.bat including:

"c:\Program Files\Notepad++\notepad++.exe" %*

and I type:

C:\prog\git>git config --global core.editor C:\prog\git\npp.bat

It just works from the DOS session, but not from the git shell.
(not that with the core.editor configuration mechanism, a script with "start /WAIT..." in it would not work, but only open a new DOS window)


Bennett's answer mentions the possibility to avoid adding a script, but to reference directly the program itself between simple quotes. Note the direction of the slashes! Use / NOT \ to separate folders in the path name!

git config --global core.editor \
"'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

Or if you are in a 64 bit system:

git config --global core.editor \
"'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

But I prefer using a script (see below): that way I can play with different paths or different options without having to register again a git config.


The actual solution (with a script) was to realize that:
what you refer to in the config file is actually a shell (/bin/sh) script, not a DOS script.

So what does work is:

C:\prog\git>git config --global core.editor C:/prog/git/npp.bat

with C:/prog/git/npp.bat:

#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst "$*"

or

#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"

With that setting, I can do 'git config --global --edit' from DOS or Git Shell, or I can do 'git rebase -i ...' from DOS or Git Shell.
Bot commands will trigger a new instance of notepad++ (hence the -multiInst' option), and wait for that instance to be closed before going on.

Note that I use only '/', not \'. And I installed msysgit using option 2. (Add the git\bin directory to the PATH environment variable, but without overriding some built-in windows tools)

The fact that the notepad++ wrapper is called .bat is not important.
It would be better to name it 'npp.sh' and to put it in the [git]\cmd directory though (or in any directory referenced by your PATH environment variable).


See also:


lightfire228 adds in the comments:

For anyone having an issue where N++ just opens a blank file, and git doesn't take your commit message, see "Aborting commit due to empty message": change your .bat or .sh file to say:

"<path-to-n++" .git/COMMIT_EDITMSG -<arguments>. 

That will tell notepad++ to open the temp commit file, rather than a blank new one.

OTHER TIPS

Building on Darren's answer, to use Notepad++ you can simply do this (all on one line):

git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

Obviously the C:/Program Files/Notepad++/notepad++.exe part should be the path to the Notepad++ executable on your system. For example, it might be C:/Program Files (x86)/Notepad++/notepad++.exe .

Works like a charm for me.

Anyway, I've just been playing around with this and found the following to work nicely for me:

git config --global core.editor "'C:/Program Files/TextPad 5/TextPad.exe' -m"

I don't think CMD likes single-quotes so you must use double quotes "to specify the space embedded string argument".

Cygwin (which I believe is the underlying platform for Git's Bash) on the other hand likes both ' and "; you can specify a CMD-like paths, using / instead of \, so long as the string is quoted i.e. in this instance, using single-quotes.

The -m overrides/indicates the use of multiple editors and there is no need for a %* tacked on the end.

Edit: After updating to vim 7.3, I've come to the conclusion that the cleanest and easiest way to do this is:

  1. Add Vim's main folder to your path (Right click on My Computer -> Properties -> Advanced -> Environment Variables)

  2. Run this:git config --global core.editor "gvim --nofork '%*'"

If you do it this way, then I am fairly sure it will work with cygwin as well.

Original answer:

Even with a couple of vim-related answers, I was having trouble getting this to work with gvim under Windows (while not using a batch file or %EDITOR% or cygwin).

What I eventually arrived at is nice and clean, and draws from a few of the solutions here:

git config --global core.editor \
"'C:/Program Files/Vim/vim72/gvim.exe' --nofork '%*'"

One gotcha that took me a while is these are not the Windows-style backslashes, they are normal forward slashes.

Notepad++ works just fine, although I choose to stick with Notepad, -m, or even sometimes the built-in "edit."

The problem you are encountering using Notepad++ is related to how git is launching the editor executable. My solution to this is to set EDITOR to a batch file, rather than the actual editor executable, that does the following:

start /WAIT "E:\PortableApps\Notepad++Portable\Notepad++Portable.exe" %*

/WAIT tells the command line session to halt until the application exits, thus you will be able to edit to your heart's content while git happily waits for you. %* passes all arguments to the batch file through to Notepad++.

c:\src>echo %EDITOR%
c:\tools\runeditor.bat

Wordpad!

I'm happy using vim, but since I'm trying to introduce Git to the company I wanted something that we'd all have, and found that Wordpad seems to work okay (i.e. Git does wait until you're finished editing and close the window).

git config core.editor '"C:\Program Files\Windows NT\Accessories\wordpad.exe"'

That's using Git Bash on msysgit; I've not tried from the Windows command prompt (if that makes any difference).

I also use Cygwin on Windows, but with gvim (as opposed to the terminal-based vim).

To make this work, I have done the following:

  1. Created a one-line batch file (named git_editor.bat) which contains the following:
    "C:/Program Files/Vim/vim72/gvim.exe" --nofork "%*"
  2. Placed git_editor.bat on in my PATH.
  3. Set GIT_EDITOR=git_editor.bat

With this done, git commit, etc. will correctly invoke the gvim executable.

NOTE 1: The --nofork option to gvim insures that it blocks until the commit message has been written.

NOTE 2: The quotes around the path to gvim is required if you have spaces in the path.

NOTE 3: The quotes around "%*" are needed just in case git passes a file path with spaces.

Thanks to the SO community ... and a little research I was able to get my favorite editor, EditPadPro, to work as the core editor with msysgit 1.7.5.GIT and TortoiseGit v1.7.3.0 over WinXP SP3 ...

Following the advice above I added the path to a bash script for the code editor ...

git config --global core.editor c:/msysgit/cmd/epp.sh

However after several failed attempts at the above mentioned solutions ... I was finally able to get this working. Per EditPadPro's documentation, adding the '/newinstance' flag would allow the shell to wait for the editor input ....

The '/newinstance' flag was the key in my case ...

#!/bin/sh
"C:/Program Files/JGsoft/EditPadPro6/EditPadPro.exe" //newinstance "$*"

This is the 1 symptom of greater issues. Notably that you have something setting TERM=dumb. Other things that don't work properly are the less command which says you don't have a fully functional terminal. It seems like this is most commonly caused by having TERM set to something in your global windows environment variables. For me, the issue came up when I installed Strawberry Perl some info about this is on the msysgit bug for this problem as well as several solutions.

The first solution is to fix it in your ~/.bashrc by adding:

export TERM=msys

You can do this from the Git BASH prompt like so:

echo "export TERM=msys" >> ~/.bashrc

The other solution which ultimately is what I did because I don't care about Strawberry Perl's reasons for adding TERM=dumb to my environment settings is to go and remove the TERM=dumb as directed in this comment on the msysgit bug report.

Control Panel/System/Advanced/Environment Variables... (or similar, depending on your version of Windows) is where sticky environment variables are set on Windows. By default, TERM is not set. If TERM is set in there, then you (or one of the programs you have installed - eg. Strawberry Perl) has set it. Delete that setting, and you should be fine.

Similarly if you use Strawberry Perl and care about the CPAN client or something like that, you can leave the TERM=dumb alone and use unset TERM in your ~/.bashrc file which will have a similar effect to setting an explicit term as above.

Of course all the other solutions are correct that you can use git config --global core.editor $MYFAVORITEEDITOR to make sure that git uses your favorite editor when it needs to launch one for you.

For Atom you can do

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

and similar for VSCode

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

which will open up an Atom or VSCode window for you to commit through,

or for Sublime

git config --global core.editor "subl -n -w"

Edit .gitconfig file in c:\Users\YourUser folder and add:

[core]
editor = 'C:\\Program files\\path\\to\\editor.exe'

Vim/Gvim works well for me.

>echo %EDITOR%

c:\Vim\Vim71\vim.exe

I had PortableGit 1.6 working fine but after upgrading to PortableGit-1.7 windows release had problems. Some of the git commands opens up Notepad++.exe fine but some don't, especially git rebase behaves differently.

Problem is some commands run windows cmd process some use unix cmd process. I want to give startup attributes to Notepad++ editor so need to have a customized script. My solution is this.

1) Create a script to run an appropriate text editor. Script looks weird but handles both windows and unix variation. c:/PortableGit/cmd/git-editor.bat

#!/bin/sh
#open a new instance

function doUnix() {
  "c:\program files\notepad++\notepad++.exe" -multiInst -nosession -notabbar $*
  exit
}

doUnix $*

:WINCALL
"c:\program files\notepad++\notepad++.exe" -multiInst -nosession -notabbar %*

2) Set global core.editor variable Script was saved to git/cmd folder so its already in a gitconsole path, this is mandatory as full path may not work properly.

git config --global core.editor "git-editor.bat"

Now I can run git commit -a and git rebase -i master commands. Give it a try if you have problems in Git windows tool.

I use git on multiple platforms, and I like to use the same git settings on all of them. (In fact, I have all my configuration files under release control with git, and put a git repository clone on each machine.) The solution I came up with is this:

I set my editor to giteditor

git config --global core.editor giteditor

Then I create a symbolic link called giteditor which is in my PATH. (I have a personal bin directory, but anywhere in the PATH works.) That link point to my current editor of choice. On different machines and different platforms, I use different editors, so this means that I don't have to change my universal git configuration (.gitconfig), just the link that giteditor points to.

Symbolic links are handled by every operating system I know of, though they may use different commands. For Linux, you use ln -s. For Windows, you use the cmd built-in mklink. They have different syntaxes (which you should look up), but it all works the same way, really.

Based on VonC suggestion above, this worked for me (was driving me crazy):

git config --global core.editor "'C:/Program Files (x86)/Sublime Text 3/subl.exe' -wait"

Omitting -wait can cause problems especially if you are working with gerrit and change ids that have to be manually copied to the bottom of your commit message

This is my setup to use Geany as an editor for git:

git config --global core.editor C:/path/to/geany.bat

with the following content in geany.bat :

#!/bin/sh
"C:\Program Files\Geany\bin\Geany.exe" --new-instance "$*"

It works in both DOS console and msysgit.

I use Cygwin on Windows, so I use:

export EDITOR="emacs -nw"

The -nw is for no-windows, i.e. tell Emacs not to try and use X11.

The Emacs keybindings don't work for me from a Windows shell, so I would only use this from a Cygwin shell... (rxvt recommended.)

I prefer to use emacs. Getting it set up can be a little tricky.

  1. Download emacs and unpack it somewhere like c:\emacs.
  2. Run c:\emacs\bin\addpm.exe. You need to right-click and "Run as Administrator" if you are using Windows Vista or above. This will put the executables in your path.
  3. Add (server-start) somewhere in your .emacs file. See the Emacs Windows FAQ for advice on where to put your .emacs file.
  4. git config --global core.editor emacsclientw

Git will now open files within an existing emacs process. You will have to run that existing process manually from c:\emacs\bin\runemacs.exe.

I've had difficulty getting git to cooperate with wordpad, KomodoEdit and pretty much every other editor I give it. Most open for editing, but git clearly doesn't wait for the save/close to happen.

As a crutch, I've just been doing i.e.

git commit -m "Fixed the LoadAll method"

to keep things moving. Tends to keep my commit messages a little shorter than they probably should be, but clearly there's some work to be done on the Windows version of git.

The GitGUI also isn't that bad. It takes a little bit of orientation, but after that, it works fairly well.

I needed to do both of the following to get git to launch notepad++ in windoze:

-add the following to .gitconfig:

editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin

-modify the shortcut to launch the git bash shell to run as administrator, and then use that to launch the git bash shell. I was guessing that the context menu entry "Git Bash here" was not launching npp with the required permissions.

After doing both of the above it worked.

It seems as if Git won't find the editor if there are spaces in the path. So you will have to put the batch file mentioned in Patrick's answer into a non-whitespace path.

I've just had the same problem and found a different solution. I was getting

error: There was a problem with the editor 'ec'

I've got VISUAL=ec, and a batch file called ec.bat on my path that contains one line:

c:\emacs\emacs-23.1\bin\emacsclient.exe %*

This lets me edit files from the command line with ec <filename>, and having visual set means most unixy programs pick it up too. Git seems to search the path differently to my other commands though - when I looked at a git commit in ProcMon I saw it look in every folder on the path for ec and for ec.exe, but not for ec.bat. I added another environment variable (GIT_EDITOR=ec.bat) and all was fine.

I managed to get the environment version working by setting the EDITOR variable using quotes and /:

EDITOR="c:/Program Files (x86)/Notepad++/notepad++.exe"

I'm using GitHub for Windows which is a nice visual option. But I also prefer the command line, so to make it work when I open a repo in a Git shell I just set the following:

git config --global core.editor vim

which works great.

This works for Powershell and cmder-1.2 (when used with powershell). In ~/.gitconfig

[core]
    editor = 'c:/program files/sublime text 3/subl.exe' -w

How can I make Sublime Text the default editor for Git?

Resurrecting an old thread, but I found a a beautifully simple solution posted here - although there may be a mistake in the path in which you have to copy over the "subl" file given by the author. I am running Win 7 x64 and I had to put the "subl" file in my /Git/cmd/ folder to make it work. It works like a charm though.

ATOM and Windows 10

  1. Right clicked the Atom icon at the desktop and clicked on properties.
  2. Copied the "Start in" location path
  3. Looked over there with the windows explorer and found "atom.exe".
  4. Typed this in the git bash:

    git config --global core.editor C:/Users/YOURNAMEUSER/AppData/Local/atom/app-1.7.4/atom.exe"

Note: I changed all \ for / . I created a .bashrc at my home directory and used / to set my home directory and it worked, so i assumed / will be the way to go.

When using a remotely mounted homedrive (samba share, nfs, ...) your ~/.git folder is shared acros all systems which can lead to several problems. Thus I prefer a script to determine the right editor for the right system:

#!/usr/bin/perl
# Detect which system I'm on and choose the right editor
$unamea = `uname -a`;
if($unamea =~ /mingw/i){
    if($unamea =~ /devsystem/i){#Check hostname
        exec('C:\Program Files (x86)\Notepad++\notepad++.exe', '-multiInst', '-nosession', @ARGV);
    }
    if($unamea =~ /testsystem/i){
        exec('C:\Program Files\Notepad++\notepad++.exe', '-multiInst', '-nosession', @ARGV);
    }
}
$MCEDIT=`which mcedit`;
if($MCEDIT =~ /mcedit/){
    exec($MCEDIT, @ARGV);
}
$NANO=`which nano`;
if($NANO =~ /nano/){
    exec($NANO, @ARGV);
}
die "You don't have a suitable editor!\n";

One might consider a plain shell script but I used perl as is perl is shipped with msysgit und your unixoid systems will provide one as well. Putting the script in /home/username/bin, which should be added to PATH in .bashrc or .profile. Once added with git config --global core.editor giteditor.pl you have the right editor, wherever you are.

This is working for me using Cygwin and Textpad 6 (EDIT: also working with Textpad 5 as long as you make the obvious change to the script), and presumably the model could be used for other editors as well:

~/.gitconfig:

[core]
    editor = ~/script/textpad.sh

~/script/textpad.sh

#!/bin/bash

APP_PATH=`cygpath "c:/program files (x86)/textpad 6/textpad.exe"`
FILE_PATH=`cygpath -w $1`

"$APP_PATH" -m "$FILE_PATH"

This one-liner works as well:

~/script/textpad.sh (option 2):

"`cygpath "c:/program files (x86)/textpad 6/textpad.exe"`" -m "`cygpath -w $1`"

This worked for me:

  1. Add the directory wich contains the editor's executable to your PATH variable. (e.g. "C:\Program Files\Sublime Text 3\")
  2. Reboot your computer.
  3. Change the core.editor global git variable to the name of the editor executable without the extension '.exe' (e.g. git config --global core.editor sublime_text)

That's it!

NOTE: Sublime Text 3 is the editor I used for this example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top