I often use git push --force-with-lease; it does exactly what I need. Is there a short form of the flag, like -f is for --force? If not, I would like to propose -l be added as one. I don't believe git push has an -l flag currently, and l is of course the first letter of lease.
Re: Short form of --force-with-lease
I have also thought about this.
I'd suggest a config option "push.forceFlagBehavior" that would allow to configure the behavior, one of: - "default" / "overwrite", which is currently -f, - "lease" for --force-with-lease, - "lease-includes" for --force-with-lease --force-if-includes, - possibly others.
Then, upon `git push -f`, the config option would be consulted to determine the behavior.
To get the default behavior, `-f -f` or `-F` could be used.
RE: Short form of --force-with-lease
On Thursday, April 11, 2024 1:37 PM, Kipras Melnikovas wrote:
>I'd suggest a config option "push.forceFlagBehavior" that would allow to
configure
Show 7 quoted lines
>the behavior, one of: >- "default" / "overwrite", which is currently -f, >- "lease" for --force-with-lease, >- "lease-includes" for --force-with-lease --force-if-includes, >- possibly others. > >Then, upon `git push -f`, the config option would be consulted to determine
the
>behavior. > >To get the default behavior, `-f -f` or `-F` could be used.
If this is mostly about saving typing, you could get a similar effect adding an alias. Something like
git config --global alias.pushfl 'push --force-with-lease'
Re: Short form of --force-with-lease
> If this is mostly about saving typing, you could get a similar effect adding > an alias. Something like > > git config --global alias.pushfl 'push --force-with-lease'
Correct, and I already have an alias: 'pf = push --force-with-lease --force-if-includes'.
However, I see the config option more valuable - it would protect against accidental `push -f`, which, out of habit, is very probable to run on accident. With the config option, would feel safe and wouldn't need the alias either.
Thanks.
Re: Short form of --force-with-lease
On Thu, Apr 11, 2024 at 1:34 PM Kipras Melnikovas <kipras@kipras.org> wrote:
Show 12 quoted lines
> > > If this is mostly about saving typing, you could get a similar effect adding > > an alias. Something like > > > > git config --global alias.pushfl 'push --force-with-lease' > > Correct, and I already have an alias: > 'pf = push --force-with-lease --force-if-includes'. > > However, I see the config option more valuable - it would protect against > accidental `push -f`, which, out of habit, is very probable to run on accident. > With the config option, would feel safe and wouldn't need the alias either.
It would normalize the use of `push -f` in people's muscle memory, which would be a potential disaster if someone lost their configuration, but not this muscle memory. It also would break automation/scripts - `git push` is likely used by both humans and automation (custom one-off automation like a personal script, or automation shared by many people) - if they're expecting `git push -f` to do the legacy behavior, then it'll break things if the meaning of `-f` changes. A separate flag (or just using an alias if it's for saving typing) would be safer.
> > Thanks. > >
Re: Short form of --force-with-lease
Show 18 quoted lines
> > > If this is mostly about saving typing, you could get a similar effect adding > > > an alias. Something like > > > > > > git config --global alias.pushfl 'push --force-with-lease' > > > > Correct, and I already have an alias: > > 'pf = push --force-with-lease --force-if-includes'. > > > > However, I see the config option more valuable - it would protect against > > accidental `push -f`, which, out of habit, is very probable to run on accident. > > With the config option, would feel safe and wouldn't need the alias either. > > It would normalize the use of `push -f` in people's muscle memory, > which would be a potential disaster if someone lost their > configuration, but not this muscle memory. It also would break > automation/scripts - `git push` is likely used by both humans and > automation <...>. A separate flag (or just using an alias if it's for > saving typing) would be safer.
Fair point, I retract my config option proposal. A separate flag, as proposed by OP, would make more sense. Thanks.
Re: Short form of --force-with-lease
<rsbecker@nexbridge.com> writes:
> If this is mostly about saving typing, you could get a similar effect adding > an alias. Something like > > git config --global alias.pushfl 'push --force-with-lease'
The use of --force-with-lease without specifying which commit you took lease on is not all that safe [*], so I am not sure how useful such an alias will be.
Configuring how "--force" behaves and changing it to an unadorned "--force-with-lease" is to promote a not-so-safe feature as if it is safe with false sense of safety, which is not something we would want to do.
[Footnote]
* This of course highly depends on your workflow and third-party companion tools. If you (or your IDE in the background) fetch from the remote after you started working on the commit to be force-pushed, it would update the tip of the remote-tracking branch, making --force-with-lease base its decision on a wrong commit that your work is not based on.