0

I've begun using git push --force-with-lease rather than --force in most cases for the additional branch protection:

I may even try to set this option as the default, as described here:

The main annoyance in using --force-with-lease though is the awkward phrasing and verbose syntax of typing that flag.

Git's --force and -f flags are much shorter and easier to type, but do not offer the additional safety.


Is there a short form of --force-with-lease, such as --fwl?

  • If not, is there a reason this has not been added? A more convenient flag would seemingly increase adoption of the safer feature. Has this been discussed by the creators of git?

If no such flag exists by default, how can I create such a flag or alias on my own machine?

5
  • 3
    Is there a reason why it's hard to make a git alias for this?
    – matt
    Oct 7, 2020 at 18:02
  • You actually only need to type --force- [tab].
    – TTT
    Oct 7, 2020 at 19:13
  • @TTT at least on my mostly default Mac, that does not actually autocomplete git commands. Apparently more setup is needed: stackoverflow.com/questions/14970728/…
    – pkamb
    Oct 7, 2020 at 19:16
  • 1
    @pkamb ah. I'd recommend taking the time to get that working. I would say your productivity will greatly increase if you do (assuming you use the command line regularly.) Not just for --force-with-lease, but for branch name completion, and many other options you may use that you don't have memorized (--first-parent, --set-upstream-to, etc). Having double tab ready to go to see all the options for a command is really nice. I use it so often that when I found myself in a terminal that doesn't have it, I cringe. :)
    – TTT
    Oct 7, 2020 at 19:26
  • 1
    As noted, there isn't a short name for this, but I'd argue that -f ought to be short for this and not for plain --force. Unfortunately Git is trapped in the mire of backwards compatibility here. Adding --fwl or --safeforce or something along those lines might be a good idea (although "safe force" might be overselling the concept, as it can still be used unsafely).
    – torek
    Oct 7, 2020 at 22:30

1 Answer 1

4

There is no shorthand for that option. To make a global alias, just add this to ~/.gitconfig

[alias]
        push-fwl = push --force-with-lease

where you would use the alias like -> git push-fwl

Of course, you can name push-fwl however you want to.

As for the documentation, I would assume the reason that this specific option does not have a shorthand is because of the complexity of its usage. Keep in mind that there are many ways to call --force-with-lease.

Taken from the documentation:

--[no-]force-with-lease, --force-with-lease=<refname>, --force-with-lease=<refname>:<expect>

Which means that it's a per-usage basis on how we wish to use this option. I would assume that the maintainers cannot know which of all these options would be most popular in order to make a shorthand for it.

Not to mention that --force is a better known, more frequently used option, thus makes sense to have a shorthand for it.

The documentation continue further to tell us how we might get into different situations for all these options:

--force-with-lease alone, without specifying the details, will protect all remote refs that are going to be updated by requiring their current value to be the same as the remote-tracking branch we have for them.

--force-with-lease=<refname>, without specifying the expected value, will protect the named ref (alone), if it is going to be updated, by requiring its current value to be the same as the remote-tracking branch we have for it.

--force-with-lease=<refname>:<expect> will protect the named ref (alone), if it is going to be updated, by requiring its current value to be the same as the specified value (which is allowed to be different from the remote-tracking branch we have for the refname, or we do not even have to have such a remote-tracking branch when this form is used). If is the empty string, then the named ref must not already exist.

Note that all forms other than --force-with-lease=<refname>:<expect> that specifies the expected current value of the ref explicitly are still experimental and their semantics may change as we gain experience with this feature.

Given that you can create aliases, I think that the maintainers of git don't have a good reason to provide a shorthand for a relatively obscure command option.

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.