pkamb
pkamb

Reputation: 34983

Short flag for `git push --force-with-lease`?

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 no such flag exists by default, how can I create such a flag or alias on my own machine?

Upvotes: 4

Views: 1930

Answers (1)

mnestorov
mnestorov

Reputation: 4484

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.

Upvotes: 8

Related Questions