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