27 October 2012

Emacs as default editor for Git

By default Git uses vi on Mac OS X. Since I am using Emacs as my favorite text editor, I want to use Emacs for editing my commit messages in Git too. I had just to run the following command:

git config --global core.editor emacs

The problem is, this will point Git to the Emacs coming with Mac OS X, which is a very old version. Since I am using Emacs 24 through Homebrew, I had to run the following command instead:

git config --global core.editor /usr/local/bin/emacs

Now when I am committing with git commit, Emacs will be opened in my Terminal. I can edit the commit message and as in any other editor too, I save (C-x C-s) the message and close (C-x C-c) the editor. Is the commit message empty, the commit will be abort.