Trouble setting Sublime Text as default editor for entering Git commit message I am learning git command-line. I wish to set Sublime Text as the default editor for entering commit message, when I run the git commit command from Terminal.

But when trying to do so, I am running into the following error:


  error: There was a problem with the editor ''/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl' -n -w'.
  Please supply the message using either -m or -F option.


What could be going wrong? How do I resolve the error message, and set things such that Sublime Text opens automatically for entering commit message when running git commit command from Terminal.
Start by making sure you have Sublime Text for macOS installed on your computer. You can install it using either of the following:


Download it from the official website from the download page.
If you use Homebrew, you can install it via Homebrew Cask by running the following command-line in Terminal.app in macOS:

brew cask install sublime-text


Once you have the app installed, it should be available under /Applications directory on your Mac. (Assuming that in case 1, you have copied the Sublime Text.app bundle into the /Applications folder as instructed).

Once installed, this should be the path of the Sublime Text.app bundle and the editors executable file respectively:


App bundle: /Applications/Sublime Text.app
Executable: /Applications/Sublime Text.app/Contents/MacOS/Sublime Text


Now, we'll use the executable's path above to set it as the editor for git command to use for writing commit message. Run the following command to do so:

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


Notice how we have:


Specified the path for the executable and not the app bundle.
Included the path into double-quotes
Backslash-escaped the space characters present in the path.


Once done you'd be set. Now make sure that the editor is not running, go to the Terminal, change to the directory containing your repository, stage some changes, and run the commit command. Sublime Text should be opened for you to enter the commit message. Write your commit message, save the file (you can use keyboard shortcut Command + S), and quit the editor. Your commit should get recorded.

Now that was about how to configure and use the desired editor. Whether it's a recommended approach or not is a matter of personal preference. Most folks prefer using a command-line editor which makes the overall workflow much simpler as everything gets done then and there without leaving the Terminal.

You may want to refer to this excellent post to learn in detail:


Using TextEdit as your git editor


If you have installed Sublime Text in an alternate location (such as in ~/Applications, i.e. a folder in your Home directory), you'd have to change to use the appropriate path.