Skip to content

Instantly share code, notes, and snippets.

@S3ak
Last active May 21, 2024 12:52
Show Gist options
  • Select an option

  • Save S3ak/10427958 to your computer and use it in GitHub Desktop.

Select an option

Save S3ak/10427958 to your computer and use it in GitHub Desktop.
How to set git commit editor to sublime
Method 1
git config --global core.editor "'c:/program files/sublime text 3/sublime_text.exe' -w"
Method 2
git config --global core.editor "subl -n -w"
Method 3
$ echo 'alias subl="/cygdrive/c/Program\ Files/Sublime\ Text\ 3/sublime_text.exe"' >> ~/.bashrc
@LiubovT

LiubovT commented Jul 4, 2019

Copy link
Copy Markdown

I've sent hours trying to figure this out and nothing from the list above is working. I keep on getting this message, yet I am able to launch sublime with just subl alias, but when I try to commit or merge this message pops up. I am confused, does my alias even work or not?

hint: Waiting for your editor to close the file... subl -n -w: subl: command not found
error: There was a problem with the editor 'subl -n -w'.
Please supply the message using either -m or -F option.

@jdraths

jdraths commented Aug 30, 2019

Copy link
Copy Markdown

@LiubovT subl: command not found means you don't have a symlink for the subl command. You can add this symlink per the directions here.

The only change I would make to those directions is rather than adding the symlink to ~/bin I would add the symlink to /usr/local/bin. So the command would be:

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

@okor

okor commented Sep 12, 2019

Copy link
Copy Markdown

^ I've found this to be the most durable option (on MacOS).

Step one

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Step two

git config --global core.editor "subl -n -w"

Now you should be able to use Sublime text for git stuff like editing commit messages for reverts/squashes/etc.

@wayferer

Copy link
Copy Markdown

@okor thank you!

@Tom-Pepper

Tom-Pepper commented Jan 17, 2020

Copy link
Copy Markdown

It worked! But I have another problem, maybe somebody have a solution?

git rebase -i HEAD~4
and I got an empty file.

Screenshot 2020-01-17 at 13 30 09

Also attaching a config file.
Screenshot 2020-01-17 at 13 32 19

@Alberto-GS

Alberto-GS commented Apr 21, 2020

Copy link
Copy Markdown

^ I've found this to be the most durable option (on MacOS).

Step one

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Step two

git config --global core.editor "subl -n -w"

Now you should be able to use Sublime text for git stuff like editing commit messages for reverts/squashes/etc.

It finally works! Thanks a lot @okor

@Alexander-Serov

Copy link
Copy Markdown

Thanks!

@S3ak

S3ak commented Jun 9, 2020

Copy link
Copy Markdown
Author

I have no idea why this is still active. I switched to vs-code. I'm closing this gist.

@trickyj

trickyj commented Jun 19, 2020

Copy link
Copy Markdown

For Mac
Try This : git config --global core.editor "/Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text"
Then Check : git config --global -e
Make sure you include the path in double quotes.

This works for me TOO!!!!!!!Thanks @pranitkokne

yes double quote works (y) thanks

@oltoch

oltoch commented Aug 27, 2020

Copy link
Copy Markdown

I've sent hours trying to figure this out and nothing from the list above is working. I keep on getting this message, yet I am able to launch sublime with just subl alias, but when I try to commit or merge this message pops up. I am confused, does my alias even work or not?

hint: Waiting for your editor to close the file... subl -n -w: subl: command not found
error: There was a problem with the editor 'subl -n -w'.
Please supply the message using either -m or -F option.

How did you eventually solve this cos I'm having that exact problem

@AOx0

AOx0 commented Sep 19, 2020

Copy link
Copy Markdown

This worked for me (Mac):
git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w"

Hope it helps you :D

@asarkar

asarkar commented Nov 13, 2020

Copy link
Copy Markdown

Using @pranitkokne's answer, git commit opens up a new tab in Sublime, but the prompt is not returned until I quit the editor completely. Saving and closing the tab isn't enough.

@avilafab

Copy link
Copy Markdown

For Mac
Try This : git config --global core.editor "/Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text"
Then Check : git config --global -e
Make sure you include the path in double quotes.

Thanks!

@J-A-Y-R-A-T-H-O-D

Copy link
Copy Markdown

git config --global core.editor "/Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text"

works for me, thanks mate!!

@Jake1229

Copy link
Copy Markdown

^ I've found this to be the most durable option (on MacOS).

Step one

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Step two

git config --global core.editor "subl -n -w"

Now you should be able to use Sublime text for git stuff like editing commit messages for reverts/squashes/etc.

Thank you! That works.

@krzychb

krzychb commented Oct 13, 2021

Copy link
Copy Markdown

Works for me as well. Thank you @Alberto-GS!

@yakketyyak

Copy link
Copy Markdown

git config --global core.editor "/Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text"

Great !!!
For Sublime Text 3 this is a correct path git config --global core.editor "/Applications/Sublime\ Text.app/Contents/MacOS/sublime_text"

@gerektoolhy

Copy link
Copy Markdown

This worked for me on mac:

git config --global core.editor "open -a 'Sublime Text' --wait" !

Option with git config --global core.editor "subl -n -w" didnt work, resulted in error:

$ git commit
hint: Waiting for your editor to close the file... Failed to receive exit code from application
error: There was a problem with the editor 'subl -n -w'.
Please supply the message using either -m or -F option.

@kitmw

kitmw commented Jul 14, 2022

Copy link
Copy Markdown

I'm on Sublime Text build no 4126 (up to date as of now) on mac and the executable name seems to have changed to sublime_text (rather than Sublime Text). You can check yours by going to the applications folder and right click, show package contents. The upshot is the following worked for me:
git config --global core.editor "/Applications/Sublime\ Text.app/Contents/MacOS/sublime_text"

@xsqf

xsqf commented Mar 23, 2024

Copy link
Copy Markdown

prior solutions didn't work, so here's what worked for me—

OS: macOS 14.4 23E214 arm64
Shell: zsh 5.9
CPU: Apple M2
Editor: Sublime Text 4 (Build 4169)

check out Table 4 in section git config core.editor commands for an exhaustive list of core.editor configuration commands (Pro Git 2nd Ed. Appendix C). looks helpful for other system / editor combinations, too.

solution in my case:

$ git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl --new-window --wait"

(source link and git blame in the book)


specifying the path to the macOS executable sublime_text as @kitmw mentioned (thank you for the quick name check how-to) did not behave as expected:

2024-03-22 21:44:48.432 sublime_text[45060:2846253] WARNING: -restoreStateWithCoder: called with an 
unsupported NSCoder.

ghost commented May 21, 2024

Copy link
Copy Markdown

It works on my mac. Thank you @xsqf !
macOS 13.5 Shell: zsh 5.9 CPU: Apple M2 Editor: Sublime Test 4

$ git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl --new-window --wait"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment