Make force pushes more difficult
Is your feature request related to a problem? Please describe. Today I hit 'P' to push; origin/master had new commits; I accidentally hit enter and LG force pushed, causing me a bunch of trouble to restore/obtain the lost commits since I didn't have them locally.
Describe the solution you'd like Force pushes are sometimes needed, so I don't want to ban them completely at the server level, but at the same time they happen so rarely and can be damaging enough that LG should not allow one to force push simply by accidentally hitting 'enter' one a dialog pops up.
Instead, the ideal behavior would be that LG pops up a box and the user is required to hit 'y' in order to force push; if they just hit enter then it defaults to cancelling the push. Or, it could open another box to confirm.
This should not be considered an inconvenience given how rare force pushes are. It is very easy to unconsciously hit enter when a box opens up; under no circumstances should LG do something that is potentially damaging without getting a clear confirmation from the user.
Happy to add more friction in a configurable way. I'm not yet convinced we should add more friction as a default. For many users, force pushing happens all the time (e.g. if you rebase onto the main branch or amend commits).
As for how we could add more friction: two options come to mind:
- Have a menu where the cancel option appears first
- Have a second prompt asking if the user is really sure they want to force push
I'm leaning towards the second option
@jesseduffield thx, I'd vote for the first option, since it seems a bit more friction-y, which I think would be OK if it will not be the default behavior. But either one would be better than the status quo IMO.
I don't have an opinion about which kind of friction is added, as long as it is configurable. Please don't add this by default! I totally disagree with the assessment that force-pushing is rare, I do it very often, and I would hate it to become more cumbersome. On the contrary, I'd even consider removing the prompt that we have today (also configurable, of course); personally I always hit enter mindlessly without even reading the prompt, which makes it kind of pointless for me.
Maybe this could be one config with three values ("forcePushWarning: off, normal, strong" or something to that effect).
I do force push regularly and sometimes have confirmed actions through fatfingering or accidentally typing keystrokes while the input dialog is already closed. So for some destructive actions (force push, nuking worktree, rebasing) I can see the usefulness of an optional second confirmation step to make them safer.
Agree, force push is standard when you do a lot of rebasing.
Could it be an idea to include --force-if-includes [docs]? If my understanding is correct this would force you to have "acknowledged" all commits on the remote before force pushing?
We used to, but we removed it again in #2555, the idea being that people who want this can turn it on using git config (git config --global push.useForceIfIncludes true). More discussion here.