Photo from Chile

Using TextMate as the Default Editor for Git on OS X

There are a number of Git commands which pop open a text editor which you then use to provide information. For example, if you issue the command:

view plain print about
1git commit

The editor will appear allowing you to type your commit message. The default editor that appears for me, on OS X, is vi which is a strange beast to work with if you've never encountered it before (which I hadn't, prior to using Git). I found a helpful cheat sheet, which allowed me to use the editor, but I still find it cumbersome. Thankfully it's a pretty simple matter to use a different text editor with Git. There are a number of ways of doing this, and I'm going to discuss two of them. To start, let's look at how Git decides what editor to use.

Which editor will Git use?

According to the man page for git-commit:

The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).

We're going to look at changing the EDITOR environment variable and the core.editor configuration variable.

Change the EDITOR environment variable

Simply add the following line to your .bash_profile:

view plain print about
1export EDITOR="/usr/bin/mate -w"

This will cause Git to use TextMate, and may also allow other command line tools to use it as well.

Change the core.editor configuration variable

Issue the following command:

view plain print about
1git config --global core.editor "mate -w"

This is useful if you only want to change the behaviour of Git, and not affect the rest of your environment.

Related Blog Entries