1

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?

5

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.)

1

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

The hint is in (magit) Popup Buffers and Prefix Commands:

   Most popups set their initial arguments according to the
corresponding ‘magit-*-arguments’ variable.  Two popups, the log and
diff popups (see Logging and Diffing), may behave a bit
differently, depending on the value of ‘magit-use-sticky-arguments’.

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

Sure enough, we can customise the magit-push-arguments variable:

(setq magit-push-arguments '("--force-with-lease"))

or

(with-eval-after-load 'magit
  (add-to-list 'magit-push-arguments "--force-with-lease"))

or, when Magit is already loaded, via

M-xcustomize-variableRETmagit-push-argumentsRET.

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.