As per Magit's visual walkthrough, it is possible to save some configs as defaults, e.g: for diffing (section "Changing diff arguments").

I went through the documentation, but did not find anything referencing how to save configs for pushing. All I found was this bit from magit-remote.el library, with which I can figure out how to add more configurations to magit-push-popup:

   (magit-define-popup-switch 'magit-push-popup
   ?X "My flag" "--force-with-lease")

How can I set --force-with-lease as default when pushing?

2 Answers 2


The recommended way to set or save a popup's arguments is to do so from the popup.

A few commands are available in every popup. To show them press C-t. Once you have done that you will see the bindings and descriptions of two commands that are relevant to your question:

  • C-c C-c Set defaults
  • C-x C-s Save defaults

Magit's visual walkthrough mentions that:

Usually arguments are just used once. When you later enter the same popup again, then it is not enabled anymore. However, you can save the arguments you want to be used by default. To do so, enter the popup, set the arguments as desired, and then instead of invoking an action, type C-c C-c to save them as the default for the current popup. These settings persist between Emacs sessions.

C-c C-c is only one of the commands that is available in all popups. To show them all, type C-t.

(Yes, this should say "set" instead of "save.)


I went through the documentation, but did not find anything referencing how to save configs for pushing.

The hint is in (info "(magit) Transient Arguments and Buffer Variables"):

The infix arguments of many of Magit’s transient prefix commands cease
to have an effect once the ‘git’ command that is called with those
arguments has returned.  Commands that create a commit are a good
example for this.  If the user changes the arguments, then that only
affects the next invocation of a suffix command.  If the same transient
prefix command is later invoked again, then the arguments are initially
reset to the default value.  This default value can be set for the
current Emacs session or saved permanently, see (transient)Saving
Values.  It is also possible to cycle through previously used sets of
arguments using ‘M-p’ and ‘M-n’, see (transient)Using History.

Following the cross-reference to (info "(transient) Saving Values"):

After setting the infix arguments in a transient, the user can save
those arguments for future invocations.


‘C-x s’     (‘transient-set’)

     This command saves the value of the active transient for this Emacs

‘C-x C-s’     (‘transient-save’)

     Save the value of the active transient persistently across Emacs

 -- User Option: transient-values-file

     This file is used to persist the values of transients between Emacs

How can I set --force-with-lease as default when pushing?

Given the abvove, it's sufficient to enable it once, and then persist that setting by invoking C-x C-s (transient-save).

  • I only have the function magit-push-arguments defined (not the variable described above) that evaluates to ("--force-with-lease"). How do I make it default to empty list instead? Do I need to override the function or should I set a new variable magit-push-arguments to nil?
    – Nordlöw
    Feb 10, 2021 at 11:34
  • 1
    @Nordlöw This part of Magit has been rewritten since I originally wrote this answer. It now relies on the Transient package for setting/resetting/persisting argument values, so I have rewritten my answer accordingly. Magit does not default to enabling --force-with-lease, so there is something already in your config causing that. Check the contents of your transient-values-file.
    – Basil
    Feb 10, 2021 at 12:23

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.