Setting up sublimetext 3 as git commit text editor
GitSublimetext3Git Problem Overview
I'm having trouble setting up sublime as my git commit message editor.
Using:
git config --global core.editor "subl"
Error: error: cannot run subl: No such file or directory error: unable to start editor 'subl' Please supply the message using either -m or -F option.
subl work perfectly otherwise.
Git Solutions
Solution 1 - Git
For what it's worth, here's how I solved it:
-
Run in Terminal:
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
This adds a subl
alias to /usr/local/bin/
pointing to Sublime Text 3 app’s binary file. Now running subl
in Terminal will launch Sublime Text 3 app.
-
Run in Terminal:
git config --global core.editor "subl -n -w"
This adds editor = subl -n -w
to the [core]
section of the ~/.gitconfig
file. Now running git commit
in Terminal will launch Sublime Text 3 app (subl
) in a new window (-n
), and the command line will wait (-w
) until the commit message is saved and closed.
Image of final workflow added in response to clarifying question in comments below:
Official Sublime Text 3 doc: http://www.sublimetext.com/docs/3/osx_command_line.html
Solution 2 - Git
You can solve this by putting in a full path
git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w"
Source: OS X Command Line
EDIT: If the name of the app is not Sublime Text.app
you will want to replace that with the correct name.
Solution 3 - Git
Sublime Text 2
git config --global core.editor "'c:/program files/sublime text 2/sublime_text.exe' -n -w"
Sublime Text 3 ( Tested this on my Windows 10 MS Surface Pro 3 )
git config --global core.editor "'C:/Program Files/Sublime Text 3/subl.exe' -n -w"
You can also add following line to your .gitconfig file
[core]
editor = "'C:/Program Files/Sublime Text 3/subl.exe' -n -w"
Hope it helps.
Solution 4 - Git
I found out that I receive messages like:
subl -n -w: subl: command not found.
error: There was a problem with the editor 'subl -n -w'
error: There was a problem with the editor 'subl'
even though Sublime works well and can be launched from Terminal.
To fix it, run the following in Terminal:
git config --global core.editor " 'XXXXX' -n -w"
while 'XXXXX' is the path which Sublime is launched from.
It could be /usr/bin/subl
as Pranav Misra mentioned, or /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl
, or whatever you put in the symlink you have created.
Solution 5 - Git
I'm new to the community, and apologize if the answer is not in the proper format.
For me the following things worked for Sublime 3 git config --global core.editor " '/usr/bin/subl' -n -w"
Thank you all.
Solution 6 - Git
To add sublime Text as the default text editor , first create a symlink :
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Also , make it the default editor for any time when input is asked by
export EDITOR='subl -w'
Finally ,
git config --global core.editor "subl -n -w"
Solution 7 - Git
I tried all of these answers, but nothing worked. ~/.gitconfig showed that sublime was set, but git wouldn't pick up the change. In the end, I restarted my macbook, and that did it. srsly.
git config --global core.editor "subl -n -w"