How can I make Sublime Text the default editor for Git?

GitEditorDefaultSublimetextGit Config

Git Problem Overview


I have a problem setting Sublime Text 2 as the core.editor with git.

I've read through every post I could find addressing the problem, but still nothing is working for me. I am running Windows.

I have done:

git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe'"

and tried that with various arguments like -m. When I open my .gitconfig, this is what is in there:

[user]
    name = Spencer Moran
    email = [email protected]
[core]
    editor = 'C:/Program Files/Sublime Text 2/sublime_text.exe'

If I go to Git and type:

README.markdown --edit

the README file opens in Notepad, not Sublime Text.

Does anyone have any idea what I'm doing wrong or how I could fix this?

Git Solutions


Solution 1 - Git

Windows

Sublime Text 2 (Build 2181)

The latest Build 2181 just added support for the -w (wait) command line argument. The following configuration will allow ST2 to work as your default git editor on Windows. This will allow git to open ST2 for commit messages and such.

git config --global core.editor "'c:/program files/sublime text 2/sublime_text.exe' -w"
Sublime Text 3 (Build 3065)

Sublime Text 3 (Build 3065) added the subl.exe command line helper. Use subl.exe -h for the options available to you. I have hot_exit: true and remember_open_files: true set in my Sublime Text user settings. I have found the following to git config to work well for me.

git config --global core.editor "'c:/program files/sublime text 3/subl.exe' -w"

Mac and Linux

Set Sublime as your editor for Git by typing the following command in the terminal:

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


With this Git config, the new tab is opened in my editor. I edit my commit message, save the tab (Ctrl+S) and close it (Ctrl+W).

Git will wait until the tab is closed to continue its work.

Solution 2 - Git

You can use this command on Mac and Linux:

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

Solution 3 - Git

For Mac & Sublime Text 3:

If git config --global core.editor "subl -n -w" doesn't work, use this git config command:

$ git config --global core.editor "'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' -n -w"

Note: it does not contain escaping backslashes.

Solution 4 - Git

For Mac OS X in the file ~/.gitconfig under [core] I had to put this code to solve the issue on my end.

editor = /Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl  -n -w

This was when subl was working fine but git was unable to access it. And was displaying these errors

subl -n -w: subl: command not found
error: There was a problem with the editor 'subl -n -w'.

Solution 5 - Git

what worked for me in cygwin/zsh:

in /usr/local/bin create subl_git file

#!/bin/bash
/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe -w -n `cygpath -w $@`

in gitconfig:

editor = /usr/local/bin/subl_git

Solution 6 - Git

With Sublime Text 2 and the following configuration, if nothing happens when you close the git commit's comment file :

git config --global core.editor "'c:/program files/sublime text 2/sublime_text.exe' -w"

If the git commit doesn't finish when you close the COMMIT_EDITMSG comment file in Sublime, I've found this is probably because you are running CMD in administrator mode (and have a Sublime Text already opened in non admin mode). I had the same problem and it worked for me when I started my CMD in normal mode.

Ps : just wanted to answer to the problem @david pointed out in the accepted answer's comments, but I couldn't post comment since I'm new here... so I've made a new answer, because I think this can be useful to some people encountering the problem.

Solution 7 - Git

I just successfully made it with the help of PowerShell (command line tools for windows, which is also be use as the default command line on GithubforWindows)

Just make a folder "WindowsPowerShell" on "C:\Users%username%\My Documents". Then, create a file called "profile.ps1". Make sure that you have the correct file extension, .ps1 and not .txt. inside the profile.ps1, put this line to set an alias command:

Set-Alias subl 'c:\program files\sublime text 2\sublime_text.exe'

Make sure the sublime directory on your machine is correct. You can also see the configuration details in here.

Now, I can edit files with Sublime Text 2 via PowerShell command just by typing:

subl filename

Hopefully this is usefull...

Solution 8 - Git

I've faced the same problem with git editor in Windows this evening, and finally I've got it.

You'll need to set your editor path with the bash syntax and using the DOS 8.3 format to avoid spaces:

This doesn't work (for me):

git config --global core.editor "C://Program files/Sublime Text/sublime_text.exe"

This do:

git config --global core.editor /C/PROGRA~1/SUBLIME~1/sublime_text.exe

You can get the DOS 8.3 name for a directory with dir /x

Solution 9 - Git

On MacOS(Mojave) below is working for me for Sublime 3:

git config --global core.editor "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl -n -w"

Solution 10 - Git

I was just struggling with this for some reason, none of the examples above quite worked for me. This was my solution however:

 git config --global core.editor "'c:/<path to sublime>/sublime_text.exe' -w $*"

You specifically need the ' ' around the path and the $* at the end of the args, all in " ".

Solution 11 - Git

For MAC Users I can say for Sublime use the following:

First Check the .gitconfig file using command:

  1. cd ~
  2. ls -la
  3. cat .gitconfig

Now one can add this configuration:

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

Where l1 will tell to start at line 1.

Solution 12 - Git

If you are Mac User, then here is how:

git config --global core.editor '/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'

Solution 13 - Git

well, i had some trouble invoking notepad++ from gitbash even after setting it as my core.editor.

i got it all solved by appending the below line to my .bashrc file in my gitbash installation directory.

alias npp='winpty "C:/Program Files (x86)/Notepad++/notepad++.exe"'

so, i can invoke notepad++ with the alias "npp". i feel this can help you if you change the directory to the respective editor you want to use.

Solution 14 - Git

For Windows 7 I have found the following solution works:

git config --global core.editor "C:/Program\ Files/Sublime\ Text\ 2/sublime_text.exe -n -w"

Solution 15 - Git

On Windows, if you are installing git, you can select other editor and give the following command line. C:\Program Files\Sublime Text 3\sublime_text.exe -w Installer Image

Solution 16 - Git

I haven't seen any instances of updates regarding Windows allowing Git installation to actively pick Sublime Text as your default text editor without all the sturm und drang of the original override codes... Sublime Text shown as option in (re)installation of Git

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSpencer MoranView Question on Stackoverflow
Solution 1 - GitjrotelloView Answer on Stackoverflow
Solution 2 - GitsfufoetView Answer on Stackoverflow
Solution 3 - Gitnu-boView Answer on Stackoverflow
Solution 4 - GitAhmad AwaisView Answer on Stackoverflow
Solution 5 - GitmeeechView Answer on Stackoverflow
Solution 6 - GitFrancoisView Answer on Stackoverflow
Solution 7 - GitErwin ZhangView Answer on Stackoverflow
Solution 8 - GitDiego BuendiaView Answer on Stackoverflow
Solution 9 - GitPratik PatelView Answer on Stackoverflow
Solution 10 - Gitjustin.m.chaseView Answer on Stackoverflow
Solution 11 - GitbvmCoderView Answer on Stackoverflow
Solution 12 - GitmainframerView Answer on Stackoverflow
Solution 13 - GitOLATOMIDEView Answer on Stackoverflow
Solution 14 - Gittscott1View Answer on Stackoverflow
Solution 15 - GitXavier JohnView Answer on Stackoverflow
Solution 16 - GitAngelfirenzeView Answer on Stackoverflow