I'm using git to maintain a web site located on a remote server. My workflow has been as follows:

  1. Stage and commit changes to the web site (can do with Magit)

  2. ssh to the remote site and pull the changes into the repository that is located there, updating the working tree (cannot do with Magit)

  3. Still in the script at the remote site, run make on the new working tree

  4. Back in emacs, fetch from the remote repository, so that Magit knows things are up to date

Steps 2 and 3 are implemented by a single shell script, but now that I'm addicted to magit, leaving magit to run a shell script seems an enormous imposition. My question is twofold:

  • How can I integrate steps 2, 3, and 4 into a single emacs command? The magit documentation has a section entitled "Plumbing," and there are some hints there, so I might be able to make progress on my own.

  • How can I add the new command as an option to Magit's context-sensitive push menu, which pops up when I use the capital P? This one I have no idea how to do. Can anybody help?

2 Answers 2


For steps 2 and 3, you can just use shell-command and ssh to accomplish this from emacs.

To do 4, you can use magit-fetch-all-no-prune.

You can wrap this into a function like

(defun aec/ssh-make-and-fetch ()
  (shell-command "ssh [email protected] \"cd project && make\"")

Then you can add an action to the push popup with magit-define-popup-action. The push popup is magit-push-popup.

In this example, I'll bind it to the key !

(magit-define-popup-action 'magit-push-popup 
  "Make remotely"

To configure this after magit loads, you can use eval-after-load in your init.el (assuming you aren't already using something like use-package).

(eval-after-load "magit"
  '(magit-define-popup-action 'magit-push-popup
     "Make remotely" 
  • I'll have to try to get the information [email protected] and project from the URL of the remote repo in magit, but I can probably figure that out, thanks. Commented Aug 28, 2016 at 13:21
  • Where do I add the action magit-define-popup-action? I'd like to run this when the magit package is loaded, but I have not figured out how to do this. Commented Aug 30, 2016 at 18:54
  • 1
    @NormanRamsey updated my answer with an example using eval-after-load Commented Aug 31, 2016 at 15:45

This has changed recently with newer versions of Magit which use "Transient" to accomplish this:

(transient-append-suffix 'magit-push "m" '("!" "Make remotely" 'aec/ssh-make-and-fetch))

Reference: https://github.com/magit/magit/wiki/Converting-popup-modifications-to-transient-modifications

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.