5

Despite similar questions that have been posted in the community, I have not seen this specific question addressed.

I am trying to change the default text editor used by git to Sublime. I am using a Windows machine and downloaded Sublime 3.

Initially, I was running the command git config --global core.editor "'C:\\Program Files\\Sublime Text 3\\sublime_text.exe' -n -w" in Git Bash, then when I ran a git commit it did not open an editor (it just used the Git Bash "editor").

However, when I add the flag -m to my git config: --global core.editor "'C:\\Program Files\\Sublime Text 3\\sublime_text.exe' -n -w -m" and run Git commit it now opens up the Notepad editor.

Note I have not changed any of the path or default text editor settings in Windows, I am only trying to have Sublime open up when running git commands.

Ryan Chase
  • 2,384
  • 4
  • 24
  • 33
  • 2
    Can you please update your question with the output of `git config --list --show-origin | grep -i core.editor` ? This will let us know if your configuration is correct and is not being overridden. – Ashutosh Jindal Nov 24 '16 at 19:03
  • @AshutoshJindal The output of `git config --list --show-origin | grep -i core.editor` produces this result: _file:C:/Users/ryanj/.gitconfig core.editor='c:/program files/sublime text 3/subl.exe' -w file:.git/config core.editor=notepad_ – Ryan Chase Nov 25 '16 at 04:39
  • FYI, the "Git Bash editor" is called Vim. – Code-Apprentice Nov 25 '16 at 04:44
  • Did you read [this answer](http://stackoverflow.com/a/2596835/1440565)? – Code-Apprentice Nov 25 '16 at 04:48
  • @Code-Apprentice yes, I read the answer but potentially I'm missing something- is there something specific that you're pointing to? – Ryan Chase Nov 25 '16 at 05:17
  • Although the original question is about vim, the answer I linked shows how to manually edit .gitconfig to configure sublime text. – Code-Apprentice Nov 25 '16 at 05:19
  • Also, run the command shown in the first comment and edit your question to show the output – Code-Apprentice Nov 25 '16 at 05:20
  • @Code-Apprentice I would prefer to understand what the true issue is (as a learning experience) vs. resorting to manually changing the .gitconfig. I ran the code in the first comment and responded with the results in the second comment. – Ryan Chase Nov 27 '16 at 01:10
  • You should edit your question to include the requested information instead of posting it add a comment. – Code-Apprentice Nov 27 '16 at 04:31

1 Answers1

5

Try this:

git config --global core.editor "'c:/program files/sublime text 3/subl.exe' -w"

This worked for me (i.e. on performing a git commit a Sublime Text window opened up where I was able to type the commit message and after saving and closing the window, I checked that this commit had the commit message that I had just typed in with a git show) on Windows 10 with Git for Windows version 2.10.2 and Sublime Text 3 build 3126

Note that the windows command line helper subl.exe was introduced in Build 3065 on 27 August 2014, so this should work on any build including and after #3065 :

enter image description here

Update: Git config scopes!

The output that OP posted in response to the first comment clearly shows the problem:

Command:

git config --list --show-origin | grep -i core.editor

file:C:/Users/ryanj/.gitconfig core.editor='c:/program files/sublime text 3/subl.exe' -w 
file:.git/config core.editor=notepad

OP's has a repository level configuration for core.editor which is notepad and overrides the global configuration which is set to what he expects (i.e. Sublime Text 3).

To fix this, run the following:

git config --unset core.editor

and confirm that git config --list --show-origin | grep -i core.editor shows you only ONE configuration file (i.e. c:/users/ryanj/.gitconfig) with Sublime Text 3 set as the editor.

Ashutosh Jindal
  • 18,501
  • 4
  • 62
  • 91
  • @Ashtosh Jindal I ran the command you listed: `git config --global core.editor "'c:/program files/sublime text 3/subl.exe' -w"`, but when I run `Git commit` it's still opening in Notepad. Further, when I run `git var GIT_EDITOR` it lists "notepad" – Ryan Chase Nov 25 '16 at 04:31
  • Have updated my answer, try running `git config --unset core.editor` and re-run `git config --list --show-origin | grep -i core.editor` and post output. – Ashutosh Jindal Nov 25 '16 at 08:49
  • @Ashtosh Jindal that worked! Now running `git config --list --show-origin | grep -i core.editor`only produces one line: *$ git config --list --show-origin | grep -i core.editor file:C:/Users/ryanj/.gitconfig core.editor='c:/program files/sublime text 3/subl.exe' -w*. Furthermore, running `git commit` opens Sublime Text. Thanks! – Ryan Chase Nov 27 '16 at 16:42