0

I am learning the basics of Git and have run into an issue while trying to use Sublime 2 as my default text editor for commit messages.

I am using a Mac and the Sublime text editor(Version 2.0.2, Build 2221)

As per instructions on help.github I used the following line:

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

However, when I attempt a git commit command I get the following message:

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.

I know that subl and subl -n -w work as I have tried them in isolation and they launch the editor. So the issue must be when the editor is opened from the git commit command.

I have looked at the questions and answers from 1, 2 & 3 and attempted the solutions but haven't been able to resolve my issue.

Community
  • 1
  • 1
ascar
  • 3
  • 1
  • 1
    On your Mac, where is the `subl` binary? That is, what does `which subl` say? Next, check what your `$PATH` is set to when git runs a sub-command (e.g., set `core.editor` to `env` temporarily and run `git config -e` or something, so you can inspect the `PATH` setting). Probably you need to fiddle with your `.profile` or `.cshrc` as they are probably taking the directory with `subl` out of your path. – torek Jan 30 '16 at 19:47
  • Thanks for the help. Sorry if this isn't exactly what you asked for but I am new to the command line. i) `which subl` command did not return anything. ii) `git config e` returned the following error: `env: /Users/My_Name/File_Name/.git/config: Permission denied error: There was a problem with the editor 'env'.` – ascar Jan 30 '16 at 22:44
  • Someone posted a solution on another forum. The command was `git config --global core.editor "'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl' -n -w"`. Does this indicate that the error is the symlink? If so, could someone please post the correct way to establish the symlink so that the command `git config --global core.editor "subl -n -w"` can work – ascar Jan 30 '16 at 23:52
  • That the full path works still implies that your `$PATH` is wrong, because in general you want things you intend to run (like `.../bin/subl`) directly on your `$PATH`. I'm not sure what symlink you mean, there is none in your posting nor in the linked help.github.com. – torek Jan 31 '16 at 04:30

2 Answers2

1

This answer assumes Git and Sublime Text 2 are properly installed. See this page if you haven't already updated to the latest version of Git for Mac: https://git-scm.com/download/mac

  1. Open Terminal.
  2. Run the command cd /usr/local/bin and verify /usr/local/bin exists. Create /usr/local/bin if necessary.
  3. Run the command echo $PATH and verify bin:/usr/local/bin is present in the path. Add bin:/usr/local/bin to the path if necessary.
  4. Run the command ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
  5. If you get a Permission Denied error after performing step 4, run the command sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl and enter your password when prompted.
  6. Run the command subl and verify Sublime Text 2 opens. Close Sublime Text 2.
  7. Run the command git config --global core.editor "subl -n -w". Sublime Text 2 should now be configured as your editor for Git commit messages.
plr108
  • 1,201
  • 11
  • 16
1

I encountered the same error trying to configure Sublime Text 3 for git commit messages on Mac. Like you, the subl terminal command launched Sublime Text 3 but produced an error when used with git commit.

I initially tried git config --global core.editor "subl -n -w" and got:

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.

Then I tried the following, substituting subl with the absolute path:

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

and received the following error:

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

This was because the absolute file path contained an escaping backslash that is unnecessary. Once I removed the backslash it worked! The correct git config command is:

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

Ta daa!

nu-bo
  • 441
  • 4
  • 5