Very often I want to commit a change in magit and push it straight after.

With the default magit keybindings, I have to press C-c C-c P u. How can I do this in a single command/keystroke?

2 Answers 2


This should do the trick:

(add-hook 'git-commit-setup-hook
          (lambda ()
            (add-hook 'with-editor-post-finish-hook
                      (lambda ()
                        (call-interactively #'magit-push-current-to-upstream))
                      t t)))

But I think you should neither push to the upstream nor push right after committing. You should (usually) push to the push-remote instead and you should give yourself a change to notice a mistake before you have to choose between force-pushing or adding a new commit to undo the mistake. But that's just me, if you want to push right away, then by all means do that.

The code above arranges for the push to always happen right after committing. You'll have to make adjustments if you only want it to happen "very often".


You can define a command for this and bind it to a key:

(defun my-commit-and-push (prefix)
  (interactive "P")
  (add-hook 'with-editor-post-finish-hook
            (lambda ()
              (call-interactively #'magit-push-current-to-upstream))
            t t)
  (with-editor-finish nil))

(define-key with-editor-mode-map (kbd "<f12>") #'my-commit-and-push)

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.