Setting up sublimetext 3 as git commit text editor
Asked Answered
A

7

65

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.

Allegra answered 25/3, 2014 at 10:34 Comment(0)
M
73

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.

Monetta answered 25/3, 2014 at 10:45 Comment(4)
Your answer is correct but it didn't solve my problem, I must have a wider configuration issue.Allegra
No, I had to use this git config --global core.editor '/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'Emlyn
This is not the right answer. The second one should be accepted.Entail
Thanks for the pointer, corrected the command line options which I misses first time round.Matriculation
P
134

For what it's worth, here's how I solved it:

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

2) 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:

enter image description here

Official Sublime Text 3 doc: http://www.sublimetext.com/docs/3/osx_command_line.html

Piperidine answered 12/8, 2014 at 3:26 Comment(8)
what it means and the command line will wait (-w) until the commit message is saved. I write comment in sublime open file and press W but do not ends. how to do it?Waterborne
@diEcho, just save and close the Sublime window containing your commit message, and switch to Terminal again if you aren't switched there automatically. The -w at the end of the string in the Terminal command is an optional flag to trigger a 'wait'—you don't need to type it again.Piperidine
when I am about to close it ask to save on some location. where do I save this fileWaterborne
@diEcho, it shouldn't ask where to save. The file should automatically be named COMMIT_EDITMSG and its location should automatically be .git (visible on Mac by command-clicking the filename in the Sublime window's title bar). All that should be necessary (once steps 1 & 2 above are complete) is to run git commit in Terminal, write your commit message in the file that auto-launches in Sublime, save that Sublime file, and close that Sublime window. Your file in Sublime was automatically created, yes? And your window in Sublime was automatically launched?Piperidine
@diEcho, I've added an image above hopefully to help.Piperidine
I have performed steps 1 and 2, but when I save and exit, the terminal just hangs...Why could that be?Efficacious
I have the same issue as @layser. git just sites there and does nothing after saving and closing sublimeText3.Chile
The difference that I've noticed is whether sublime is already running or not. If it's not running, it's possible that several windows got spawned (from a previous session), and you have to close all of them to get it to save. If it is already running, it creates a new process with one window, and behaves how you'd expect.Helm
M
73

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.

Monetta answered 25/3, 2014 at 10:45 Comment(4)
Your answer is correct but it didn't solve my problem, I must have a wider configuration issue.Allegra
No, I had to use this git config --global core.editor '/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'Emlyn
This is not the right answer. The second one should be accepted.Entail
Thanks for the pointer, corrected the command line options which I misses first time round.Matriculation
D
16

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.

Damal answered 7/8, 2016 at 5:28 Comment(1)
Add the -n option if you want it to open in a new window!Arenicolous
A
8

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.

Alcina answered 30/10, 2015 at 16:24 Comment(1)
Yup, I was struggling with escape sequences and this solved my problem. I don't know whether the space character right after the " is necessary, and I don't want to right now.Maag
M
4

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.

Meadors answered 13/10, 2015 at 13:7 Comment(0)
L
3

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"
Lyall answered 18/2, 2017 at 22:20 Comment(0)
W
1

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"

Waine answered 7/4, 2018 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.