Skip to content

Instantly share code, notes, and snippets.

@S3ak
Last active May 21, 2024 12:52
Show Gist options
  • Save S3ak/10427958 to your computer and use it in GitHub Desktop.
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
@kev5
Copy link

kev5 commented Jun 18, 2018

For Mac:
git config --global core.editor "subl -n -w"

@davidshare
Copy link

For Mac:
git config --global core.editor "subl -n -w"

I tried that and this is the error I keep getting

rror: There was a problem with the editor 'subl -n -w'.
Please supply the message using either -m or -F option.

I am using sublime text 3

@pranitkokne
Copy link

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.

@MaverickMeerkat
Copy link

Thanks PranitKokne ! Works for me!

@sebge-1
Copy link

sebge-1 commented Dec 13, 2018

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 great, thanks!

@rashadsternes
Copy link

Thanks @ PranitKokne. It works for me as well!

@gauravrock
Copy link

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

@brittanyabrahams2
Copy link

Unfortunately, I used tried using git config --global core.editor "/Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text"
and I am still getting the error "not found error: There was a problem with the editor
screen shot 2019-01-30 at 1 20 57 am
'/Applications/Sublime\Text.app/Contents/MacOS/Sublime\ Text'."
does anyone have another solution?

@Ammarpad
Copy link

Ammarpad commented Jan 30, 2019

Unfortunately, I used tried using git config --global core.editor "/Applications/Sublime\ Text.app/Contents/MacOS/Sublime\ Text" and I am still getting the error "not found error: There was a problem with the editor '/Applications/Sublime\Text.app/Contents/MacOS/Sublime\ Text'." does anyone have another solution?

Open the gitconfig

open .gitconfig

Paste the following

[core]
	editor = /Applications/Sublime\\ Text.app/Contents/MacOS/Sublime\\ Text

Save with Command+S

Make sure you delete any existing editor you see like

[core]
	editor = vim

@LiubovT
Copy link

LiubovT commented Jul 4, 2019

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
Copy link

jdraths commented Aug 30, 2019

@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
Copy link

okor commented Sep 12, 2019

^ 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

@okor thank you!

@Tom-Pepper
Copy link

Tom-Pepper commented Jan 17, 2020

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
Copy link

Alberto-GS commented Apr 21, 2020

^ 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

Thanks!

@S3ak
Copy link
Author

S3ak commented Jun 9, 2020

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

@trickyj
Copy link

trickyj commented Jun 19, 2020

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
Copy link

oltoch commented Aug 27, 2020

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
Copy link

AOx0 commented Sep 19, 2020

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
Copy link

asarkar commented Nov 13, 2020

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

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

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

works for me, thanks mate!!

@Jake1229
Copy link

^ 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
Copy link

krzychb commented Oct 13, 2021

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

@yakketyyak
Copy link

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

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
Copy link

kitmw commented Jul 14, 2022

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
Copy link

xsqf commented Mar 23, 2024

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.

@alexslashland
Copy link

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