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.

9
  • 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. Commented Nov 24, 2016 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 Commented Nov 25, 2016 at 4:39
  • FYI, the "Git Bash editor" is called Vim. Commented Nov 25, 2016 at 4:44
  • Did you read this answer? Commented Nov 25, 2016 at 4:48
  • @Code-Apprentice yes, I read the answer but potentially I'm missing something- is there something specific that you're pointing to? Commented Nov 25, 2016 at 5:17

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@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"
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.
@Ashtosh Jindal that worked! Now running git config --list --show-origin | grep -i core.editoronly 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!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.