I have a script to launch OSX GUI emacs from command line at:


The script looks like:

$(/Applications/Emacs.app/Contents/MacOS/Emacs --chdir $PWD "$@") &

I have configured a bash $EDITOR environment variable:

export EDITOR=/usr/local/bin/emacs

I want git to open the GUI emacs for commit messages and rebase messages

If I try to commit:

evs-MBP:skeletal-animation-system kev$ echo "cool" >> fake.js
Kevs-MBP:skeletal-animation-system kev$ git add fake.js
Kevs-MBP:skeletal-animation-system kev$ git commit
Aborting commit due to empty commit message.

This will launch the GUI prepopulated with the correct commit prompt however I believe because the command runs in the emacs command runs in the background git thinks it immediately quits.

Similiar undesired behavior happens with a rebase.

Kevs-MBP:skeletal-animation-system kev$ git rebase -i origin/master
Successfully rebased and updated refs/heads/rebase-test.

The rebase is automatically completed. I'm assuming again because the processes detaches and git thinks it completed.

I'm looking for a way to use GUI emacs with the git command line tool.

  • Remove that & sign at the end of the second line of your script to make the app stay in the foreground so git does not think the editor quit. The canonical approach is to put an editor variable in .gifconfig file instead and let git open Emacs anytime it needs editing input.
    – Emacs User
    Feb 21 '17 at 2:09
  • can I put my emacs script in the .gitconfig?
    – kevzettler
    Feb 21 '17 at 2:29
  • no, check this for config examples: git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
    – Emacs User
    Feb 21 '17 at 2:53

For my settings I have the following:

the shell script:
#!/bin/sh /Applications/Emacs.app/Contents/MacOS/Emacs "$@"

In my .zshrc: export EDITOR="/usr/local/bin/emacsclient"

In my init.el: (global-git-commit-mode t)

With these settings any git work from the command line moves to the GUI emacs.

  • getting this Symbol’s function definition is void: global-git-commit-mode when evaling
    – kevzettler
    Feb 22 '17 at 17:40
  • Check the help string for the function but you may have to do setq as part of it
    – mclear
    Feb 22 '17 at 17:59
  • this might require that you have magit installed, if you don't already (and you should install it if you haven't already done so).
    – mclear
    Feb 22 '17 at 21:07

Just set your EDITOR to run emacsclient -a "" -c (yours will be at /Applications/Emacs.app/Contents/MacOS/bin/emacsclient, I personally use some symbolic links to make life easier). Problem solved. The global-git-commit-mode is nice but not necessary. When you're done editing the message, save and C-x # to close the buffer and stop the emacsclient process.

The '-a ""' option to emacsclient will cause a new emacs in daemon mode to be started if it's not already. The -c option opens up a new GUI frame, otherwise if you didn't have one open already it would open up a terminal frame.

However, if you haven't already, you should look into magit. No finer integration between git and Emacs exists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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