Git Tips: Make Sublime as editor for git operations in macOS

I would like to use Sublime editor for git (esp. rebase) editing operations rather than default vi editor in macOS. The following steps will help you to configure Sublime as your git editor.

Make Sublime accessible from anywhere in terminal

In Sublime 3, subl command to invoke Sublime from terminal is located at

/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl

First we have to make this accessible from anywhere in terminal. For that, create a symbolic link to any folder that is already part of PATH variable

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

This is not a necessary step. But doing above will make Sublime invokable from any folder in terminal for doing other editing operations as well.

Set Sublime as git editor

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

Additional parameters do the following here:

  • -n tells git to open a new editor window
  • -w tells git to wait until the commit message is saved

This should get it working for you! Try out by running command

git rebase -i HEAD~

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: