Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text editor in git to Sublime - currently git commit commands are opening in Notepad

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.

like image 427
Ryan Chase Avatar asked Nov 24 '16 18:11

Ryan Chase


1 Answers

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.

like image 159
Ashutosh Jindal Avatar answered Sep 25 '22 17:09

Ashutosh Jindal