Enabling any text editor with git

I’m joining the party a little late, but I’ve started working with git and GitHub, both for this website, and coincidentally at work for my current project.This is a quick article about using your favorite editor to write your commit messages.

State of the art

If you happen to work with git (if not, you should download and it and play with it, it’s marvelous), you probably need to enter a commit message at some point. When you first setup your environment, no default editor is configured (on OSX, if git is installed with XCode, it might use vim as the default editor).

Checking out what is configured, it is as easy as invoking this line in the Terminal:

$ git config core.editor

Chances are, you will get an empty line as nothing is probably set.

Change the editor

Let’s say you want to use SublimeText 3. This software comes with a very handy multiplatform (Windows and OSX) CLI call subl, that you can invoke in the Terminal. To use it anywhere in your command line, you either have to put the path of the executable into the PATH variable of the Windows environment, or do a symlink on OSX (see Resources).

Open up a Terminal then type subl, you should see that it will open a new Sublime window. There is a bunch of optional parameters that you can pass to interact with Sublime, like -n for opening up a new window, or -w to wait for the files to be closed before returning.

To change the editor settings, use this command in the Terminal:

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

Now every time the command git commit will be invoked, SublimeText will be the default editor for commit messages.