I am using emacs -nw as in-place commit message editor for my git. When pressing C-c C-c in git-commit mode, I want emacs to quit automatically. Currently, .git/COMMIT_EDITMSG is saved, and the buffer is killed. Then I am left with the scratch buffer, so I have to quit emacs manually as an extra step.

My guess would be to either create some macro and bind it to some key, or add some kind of hook to git-commit-commit.

  • Not knowing more about how you are starting up / shutting down emacs for commits, I am hesitant to post an answer, but the the git-commit-commit-hook is run right before the buffer is killed. You could likely add a hook in there that determines whether or not to kill emacs and does so. Jun 15, 2015 at 15:21
  • I have added the magit tag because git-commit.el is now part of magit itself. While it is now maintained inside the magit repository it is still available as a separate package and does not depend on magit. I will try to keep it that way for as long as I can, but eventually this library might start depending on features provided by libraries that are part of the magit package.
    – tarsius
    Jun 15, 2015 at 18:07
  • @JordonBiondo, your comment looks like what I was thinking of. I just didn't find that hook. Looking at the answer below, however, I am happy I did not go that path. I have now found emacsclient to work to my advantage. I previously thought it only added complexity and tried to avoid it.
    – Martin
    Jun 18, 2015 at 10:51

1 Answer 1


git-commit.el assumes that the emacsclient is used as $GIT_EDITOR. When that is the case then aborting does still save the changes to .git/COMMIT_EDITMSG, but emacsclient then exits with a non-zero exit status, which instructs git commit to not create the commit.

It would probably be possible to make this work with emacs too, but I am not sure whether that would be worth the increased complexity. It's always preferable to use the emacsclient, most importantly this avoids an unnecessary startup delay.

So my recommendation is that you learn how to setup the emacs server and how to connect to it using emacsclient.

Or even to give Magit a try. In Magit a commit is initiated simply by pressing c c.

NOTE 1: Op also opened a related issue here, let's discuss there whether a future version of git-commit should also support using plain old emacs as editor.

NOTE 2: When OP asked the question magit v2.1.0 was not released yet. Now, after the release, git-commit-mode.el has been renamed to git-commit.el and the command that performs the commit is named with-editor-finish (the key binding is still the same : C-c C-c.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.