586

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?

Steven Penny
  • 82,115
  • 47
  • 308
  • 348
Patrick McElhaney
  • 52,844
  • 37
  • 123
  • 157
  • 7
    TLDR: put single quotes around the path to the editor executable – yoyo Mar 16 '14 at 23:19
  • Probably not helpful, but FWIW, I just use regular notepad. I did nothing to make it work. It just worked out of the box by default... – BrainSlugs83 Sep 05 '14 at 06:05
  • 12
    Update September 2015: a simple `git config core.editor notepad` is now enough. See [my updated answer below](http://stackoverflow.com/a/773973/6309). – VonC Sep 21 '15 at 11:59
  • Just a quick note that JEdit is not an appropriate editor for git. JEdit only opens one instance even for multiple files. If it was already open, git will cause it to open a new file, but then you have to completely close JEdit before git will continue. There is no command line option to cause JEdit to open a separate instance for editing the commit message. – GrantRobertson Feb 26 '17 at 03:23
  • In case anyone loves Sublime Text 3, here's my instructions for how I configured it for Windows...and Linux too: [Best settings for Sublime Text 3 as your git editor (Windows & Linux instructions)](https://stackoverflow.com/a/48212377/4561887). @yoyo, TLDR for using any text editor: put single quotes around the path to the editor executable AND use forward slashes (/) NOT back slashes (\\) in the path name to the Windows executable. – Gabriel Staples Feb 03 '18 at 19:07
  • Possible duplicate of [How do I make Git use the editor of my choice for commits?](https://stackoverflow.com/questions/2596805/how-do-i-make-git-use-the-editor-of-my-choice-for-commits) – Gabriel Staples Feb 04 '18 at 00:30

34 Answers34

588

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.

Gabriel Staples
  • 11,777
  • 3
  • 74
  • 108
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • In your shell script, you need double quotes around $*, otherwise it won't work properly for paths with spaces in them. Thanks for the thorough explanation - I'm installing git (and a bunch of other stuff) on Windows for beginning programmers, and the command line is hard enough to grok without making them learn vi commands. – Sarah Mei May 26 '09 at 00:09
  • Another concrete example: http://stackoverflow.com/questions/1634161/how-do-i-use-notepad-or-other-with-msysgit/1635493#1635493 – VonC Nov 01 '09 at 22:59
  • 1
    Following [Bennett's answer](http://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows/1431003#1431003) you do not need to create a script, you can just use an apostrophe ' inside the quotes ". – Tobias Kienzler Jul 22 '10 at 07:49
  • @Tobias: true, I have included his answer in mine, as well as the reason why I still prefer referencing a script in my `git config` settings. – VonC Jul 22 '10 at 08:23
  • Note also that you can't use "Program Files (x86)"; Git will complain about the parens. If your Git is installed there, you'll just have to put the script somewhere else. – Nate Glenn Nov 01 '12 at 00:33
  • 6
    @NateGlenn Use the shortened `dir /X` equivalent: "`PROGRA~2`" for "`Program Files (x86)`", which is a good habit to get into when using cross-platform compatible tools on Windows, which allows you to squash the whitespace. – JJ Zabkar May 08 '13 at 15:54
  • [This answer to another question](http://stackoverflow.com/questions/1634161/how-do-i-use-notepad-or-other-with-msysgit/2486342#2486342) takes this to the logical conclusion and cuts out the ".bat file" (bourne [again] shell script) – SamB Sep 10 '15 at 19:13
  • git config --global core.editor "\"C:\Program Files (x86)\Vim\vim74\gvim.exe\"" – jonincanada Sep 29 '15 at 21:34
  • You have no right to live after `-notabbar` option. It kills Notepad global options, making in unusable after every git edit. I also do not get what is the point of single-quoting the program name. – Valentin Tihomirov Dec 13 '15 at 17:02
  • @ValentinTihomirov I agree but since this old answer, I now usually use a dedicated portable Notepad++ ("portable" means uncompressed anywhere I want, as in https://notepad-plus-plus.org/repository/6.x/6.8.8/npp.6.8.8.bin.zip, not installed by an msi setup). That means I don't mind the `-notabbar`, as this notepad++ instance is dedicated for being used only as a git `core.editor`. I have another notepad++ installed elsewhere for regular text editing. – VonC Dec 13 '15 at 17:09
  • While the Microsoft Notepad may do a tolerable job of editing commit messages, I have found it is not good for editing git's config files. Notepad does not handle the end-of-line markers properly. – GrantRobertson Feb 26 '17 at 03:26
  • For anyone having an issue where N++ just opens a blank file, and git doesn't take your commit message, http://stackoverflow.com/questions/30085970/aborting-commit-due-to-empty-message. for the lazy, change your .bat or .sh file to say `"`. That will tell notepad++ to open the temp commit file, rather than a blank new one – Lightfire228 Apr 19 '17 at 04:12
  • @Lightfire228 Interesting. I have included your comment in the answer for more visibility. – VonC Apr 19 '17 at 06:29
  • [Best settings for Sublime Text 3 as your git editor (Windows & Linux instructions)](https://stackoverflow.com/a/48212377/4561887) – Gabriel Staples Feb 03 '18 at 19:01
  • I was actually coming back here to comment that the git installer now includes notepad++ as an editor, but I see that you've got a jump start ahead of me – Lightfire228 Feb 24 '18 at 17:23
  • Sir you're the Neo in the Gitrix world. if you take your glasses off you'll get back to this world :) thanks for the notepad++ solution. helped me a lot. – Reza Nov 18 '20 at 09:41
309

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.

It works like a charm for me.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Bennett McElwee
  • 22,066
  • 6
  • 47
  • 61
  • 10
    Me too! BTW, those switches are explained at C:/Program Files/Notepad++/user.manual/documentation/notepad-user-manual/command-line.html – Andrew Swan May 09 '11 at 03:21
  • 23
    Watch for Notepad++ being located in `C:\Program Files(x86)\` – mindless.panda Aug 04 '11 at 14:09
  • 2
    With this configuration, after doing a commit with git, the next time I use notepad++ the tab bar has been hidden. At least that's the case with notepad++ v5.7 and git v1.7.11. To fix it in notepad++ I have to do Settings-->Preferences-->General-->Tab Bar-->Hide uncheck. – Craig McQueen Sep 12 '12 at 00:26
  • 8
    For x64 Windows change to: git config --global core.editor "'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" – Dariusz Sep 25 '12 at 15:13
  • For sublime / windows 7, I need to have ' "" ' instead of " '' " for some reason. – Glenn Apr 03 '13 at 03:30
  • 4
    I realize I'm late to this party, but out of curiosity, does anyone know (or even remember, after all these years) why one would specify "-notabbar"? I understand the reasoning behind the other parameters (well, not sure why "-noPlugin", actually), but not this one. – Wilson F Oct 31 '14 at 20:52
  • 11
    @WilsonF The reason is because you MUST exit notepad++ for git to stop waiting for your input and continue. You don't *want* to open other tabs in this instance of Notepad++ because then your git session would appear to be frozen! Those settings do exactly the right thing: if you have Notepad++ already open, you get a new instance, that doesn't let you open other files, and that you must close when done with in order for git to know you're done editing. Works the same for commit messages. – ErikE Oct 21 '15 at 22:59
  • You have no right to live after `-notabbar` option. It kills Notepad global options, making in unusable after every git edit. I also do not get what is the point of single-quoting the program name. – Valentin Tihomirov Dec 13 '15 at 16:55
  • @ValentinTihomirov it works fine for me. Open an instance of notepad++. Use it normally. Do your git thing. A second instance opens. Close it. Everything is fine. Nothing is killed. Notepad++ works fine in others situations. I use these tools daily and promise it works. – ErikE Dec 13 '15 at 18:12
  • @ValentinTihomirov I'm saying that the tabs work fine in the regular instance of notepad++, while the instance that git launches has a single tab, which I exit from to signal to git that I'm done editing. Do NOT open more tabs in the instance git opens--that will cause problems. – ErikE Dec 14 '15 at 20:14
  • @ValentinTihomirov I don't doubt you are having problems, but I'm not, and I'm not lying! Perhaps you should look into notepad++ settings/config file? – ErikE Dec 15 '15 at 20:44
  • @ValentinTihomirov Maybe this will help you: [location of Notepad++ config files](http://superuser.com/questions/521628/where-are-notepad-config-files). When you first installed notepad++, did you check the "Don't use the %APPDATA% folder" option? Perhaps uninstalling and re-installing without checking this option could help. – ErikE Dec 15 '15 at 20:59
  • 1
    @ErikE Reinsallation fixed the thing indeed. The %APPDATA% is also immaterial. I wonder why I am so special at usually. The disappearing tabs really pissed me off. – Valentin Tihomirov Dec 15 '15 at 22:49
  • 2
    @ValentinTihomirov P.S. you single quote the program name because `Program Files` has a space in it. – ErikE Dec 15 '15 at 23:38
  • 2
    Notepad++ is now available with a 64 bit build, so it isn't located in c:\Program Files (x86) anymore. The correct command for the 64 bit build of Notepad++ is: "git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" – NMrt Sep 11 '18 at 07:27
  • 1
    @NMrt I simplified the answer based on your comment. Thanks! – Bennett McElwee Sep 12 '18 at 00:33
51

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.

Steven Penny
  • 82,115
  • 47
  • 308
  • 348
Darren Bishop
  • 2,089
  • 21
  • 15
28

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 ComputerPropertiesAdvancedEnvironment 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Nick Knowlson
  • 6,697
  • 5
  • 43
  • 62
16

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 environment variable 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
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Patrick Johnmeyer
  • 26,492
  • 2
  • 22
  • 24
  • I had trouble getting this to work under powershell. This method (http://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows/773973#773973) worked fine though. – Peter Stephens Oct 04 '09 at 23:44
12

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).

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Gavin
  • 9,497
  • 7
  • 45
  • 60
  • I liked the simplicity of this, but it didn't work for me out of the box. Here is what I tried. I receive the following error message: error: There was a problem with the editor 'C:\Program Files\Windows NT\Accessories\wordpad.exe'. – Shaun Luttin Aug 24 '13 at 02:00
  • 3
    The quotes are incorrect. You must put the **double quotes outside the single quotes**. That is, use "'C:\Program Files\Windows NT\Accessories\wordpad.exe'", and it will then work. – Shaun Luttin Aug 24 '13 at 02:10
  • You may also benefit from forward slashes (/) instead of backslashes (\\). – Chris Jones Feb 04 '14 at 18:16
  • 1
    Also, it's probably best to use "git config --global" instead of just "git config" for this. You most likely want the setting to apply to all of the git repositories on your workstation, not just the one you're in right now. – Chris Jones Feb 04 '14 at 18:17
  • @ChrisJones, No point in this case because "program files" has a space between it. – Pacerier Oct 14 '15 at 10:53
11

For Atom you can do

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

and similar for Visual Studio Code

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

which will open up an Atom or Visual Studio Code window for you to commit through,

or for Sublime Text:

git config --global core.editor "subl -n -w"
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
OmgKemuel
  • 129
  • 1
  • 6
10

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 ensures 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Tim Henigan
  • 55,120
  • 11
  • 81
  • 76
  • For people that are using msysgit (not cygwin's git) I was able to simplify this a bit. http://stackoverflow.com/questions/10564/how-can-i-set-up-an-editor-to-work-with-git-on-windows/4652019#4652019 – Nick Knowlson Jan 10 '11 at 22:04
  • On second thought it might work with cygwin as well, I'm not totally sure – Nick Knowlson Jan 10 '11 at 22:07
9

Thanks to the Stack Overflow community ... and a little research I was able to get my favorite editor, EditPad Pro, to work as the core editor with msysgit 1.7.5.GIT and TortoiseGit v1.7.3.0 over Windows XP 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 EditPad Pro'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 "$*"
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Edward J Beckett
  • 4,701
  • 1
  • 38
  • 39
  • Yeah, that double slash for the newinstance parameter should be in Editpad's docs. Thanks for noting it here! – gwideman Nov 10 '14 at 06:45
  • EditPad Pro requires command line switches like `/newinstance` to have exactly one forward slash. This is fairly normal for Windows applications. If you're invoking EditPad from a UNIX shell then you'll need to use whatever mechanism your shell offers to escape the forward slash so it does not see the switch as an absolute path and passes a single literal forward slash to EditPad's command line. – Jan Goyvaerts Nov 11 '14 at 07:53
  • 2
    If you have EditPad Pro 7, and you want to invoke EditPad Pro from a process that wants to wait on EditPad's process, then you should pass the `/wait` switch on EditPad's command line. You can use `/wait` with or without `/newinstance` to control whether a new EditPad window should be opened or whether an existing window should be reused. The process launched by your script will wait for the file to be closed regardless of whether a window was created or reused. EditPad Pro 6 and prior do not support `/wait`. – Jan Goyvaerts Nov 11 '14 at 07:57
  • @JanGoyvaerts ~ Thanks for the `/wait` flag tip sir... :) – Edward J Beckett Nov 18 '16 at 15:12
  • I was unable to get EditPad Lite working for me by using the instructions above. Perhaps it was because I was trying to invoke EditPad (through Git) by using the Windows terminal rather than Git Bash or some other UNIX shell. What worked for me was to directly edit the `[core]` section of .gitconfig to include the line `editor = "'C:/Program Files/Just Great Software/EditPad Lite 7/EditPadLite7.exe' //wait //newinstance"`. – user697473 Oct 29 '19 at 20:43
7

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

[core]
editor = 'C:\\Program files\\path\\to\\editor.exe'
guwer
  • 81
  • 1
  • 5
7

This is the one 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 information 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 - e.g. 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 in 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
lambacck
  • 9,214
  • 3
  • 31
  • 45
6

Vim/gVim works well for me.

>echo %EDITOR%

c:\Vim\Vim71\vim.exe
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Matt McMinn
  • 14,905
  • 14
  • 54
  • 68
5

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 points 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Bill
  • 536
  • 5
  • 7
  • Actually, I tried this on Windows7 and it doesn't work from msys git. It says `error: cannot spawn giteditor: No such file or directory` – DanielSank Jul 16 '14 at 04:32
5

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

The problem is some commands run the Windows cmd process and some use the Unix cmd process. I want to give startup attributes to Notepad++ editor, so I need to have a customized script. My solution is this.

  1. Create a script to run an appropriate text editor. The script looks weird, but it handles both the 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 the global core.editor variable

    The script was saved to git/cmd folder, so it's already in a gitconsole path. This is mandatory as a full path may not work properly.

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

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Whome
  • 9,559
  • 6
  • 43
  • 59
5

Based on VonC's suggestion, 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Daniel
  • 401
  • 5
  • 8
5

I needed to do both of the following to get Git to launch Notepad++ in Windows:

  • 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 Notepad++ with the required permissions.

After doing both of the above, it worked.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
JL_SO
  • 1,321
  • 16
  • 25
3

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 X Window.

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
bjnortier
  • 1,943
  • 16
  • 18
3

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 a DOS console and msysgit.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
CharlesB
  • 75,315
  • 26
  • 174
  • 199
2

I've had difficulty getting Git to cooperate with WordPad, Komodo Edit 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. It 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
J Wynia
  • 10,098
  • 4
  • 37
  • 38
2

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Michael Steele
  • 14,612
  • 2
  • 20
  • 24
2

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.

Community
  • 1
  • 1
  • 3
    This format works fine for paths with spaces: git config --global core.editor "\"c:\Program Files\textpad 5\textpad.exe\"" so it may be practical for you to avoid creating a batch file – Carl Jun 12 '09 at 09:31
1

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 Process Monitor 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Tom Dunham
  • 5,437
  • 2
  • 28
  • 25
1

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 repository in a Git shell I just set the following:

git config --global core.editor vim

which works great.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
JaKXz
  • 1,517
  • 1
  • 14
  • 31
1

This works for PowerShell and cmder 1.2 (when used with PowerShell). In file ~/.gitconfig:

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

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
rofrol
  • 12,038
  • 7
  • 62
  • 63
1

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 Windows 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
avg
  • 723
  • 1
  • 11
  • 22
1

Atom and Windows 10

  1. I right clicked the Atom icon at the desktop and clicked on properties.

  2. Copied the "Start in" location path

  3. Looked over there with Windows Explorer and found "atom.exe".

  4. I typed this in 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.

Community
  • 1
  • 1
Jonathan Ramos
  • 1,255
  • 13
  • 17
1

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

EDITOR="c:/Program Files (x86)/Notepad++/notepad++.exe"
jpjacobs
  • 8,918
  • 30
  • 39
Mike
  • 767
  • 1
  • 15
  • 25
1

to add sublime git config --global core.editor "'C:\Program Files\Sublime Text 3\sublime_text.exe'"

Ruan Nawe
  • 376
  • 4
  • 6
  • 1
    While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Donald Duck Dec 18 '20 at 11:11
0

This is working for me using Cygwin and TextPad 6 (EDIT: it is 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:

File ~/.gitconfig:

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

File ~/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:

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

"`cygpath "c:/program files (x86)/textpad 6/textpad.exe"`" -m "`cygpath -w $1`"
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
kghastie
  • 659
  • 1
  • 7
  • 14
0

This worked for me:

  1. Add the directory which 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
  • When configured this way, does Sublime Text 3 open multiple instances or handle the fact that git needs it to close to signal the end of the edit? – James World Jan 22 '14 at 13:48
  • 1
    I think it will open a new Window. You can add the --wait switch (http://www.sublimetext.com/forum/viewtopic.php?f=3&t=3257) – nikoskip Jul 30 '14 at 23:02
0

Here is a solution with Cygwin:

#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}
  1. If no path, pass no path

  2. If path is empty, pass empty path

  3. If path is not empty, convert to Windows format.

Then I set these variables:

export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'
  1. EDITOR allows script to work with Git

  2. GIT_EDITOR allows script to work with Hub commands

Source

Steven Penny
  • 82,115
  • 47
  • 308
  • 348
0

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?

The tool that I find the most useful as both my git editor and my general-purpose code editor, in both Windows and Linux, is Sublime Text 3. It works really well, but requires a little bit of setup to get it just right, so I've fully documented that fully here:

Side note about my main editor: for big projects I use Eclipse as my primary editor, and Sublime Text 3 as my git editor and additional file editor when I need to make use of its advanced features such as multi-cursor mode, vertical/column selection mode, etc. For small to medium projects I use just Sublime Text 3 by itself. For setup instructions for Eclipse, see my PDF document here.

Gabriel Staples
  • 11,777
  • 3
  • 74
  • 108
0

When using a remotely mounted homedrive (Samba share, NFS, ...) your ~/.git folder is shared across 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 it is shipped with msysgit and your Unix-like systems will usually 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.

mbx
  • 5,728
  • 6
  • 57
  • 86
-1

I just use TortoiseGit straight out the box. It integrates beautifully with my PuTTY public keys.

It has a perfect editor for commit messages.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
icc97
  • 8,746
  • 6
  • 60
  • 75