lazygit
lazygit copied to clipboard
Avoid accidental force-pushing related incidents
Is your feature request related to a problem? Please describe.
I've just accidentally erased a few commits today because my enter keypress auto-repeated, confirming the force-push.
Describe the solution you'd like
I would like to avoid these kinds of incidents, here's my ideal feature:
When requesting confirmation for force-pushing, enter will cancel the operation by default.
The confirmation window will have two options "cancel" (selected by default) and "confirm". You'll have to use the arrow key to manually select the confirm option before pressing enter in order to force-push.
I feel like this is a good compromise:
- doesn't get in your way
- prevents catastrophic mistakes
- only requires 1-2 keypress
- doesn't require fiddling with the config.
Describe alternatives you've considered
Disabling force-pushing in the config, but I do have actual reasons to use it so I'd rather not have to.
What you propose would have to be optional. "Doesn't get in your way" is very much not true for me; force-pushing is a very frequent operation for me, I don't want to have to press another key for doing that.
But I'd be open to having an option that changes the confirmation to a menu like you propose; this has come up a few times before.
I feel like having to force-push often enough that you want to save 1 keypress is probably uncommon? Either way having a way to opt-out of that confirmation is absolutely fine by me!
Having it opt-in however would defeat the purpose which is to be safe by default.
I disagree. I'm trying hard to teach people how important a good commit history is (and this includes frequent rewriting of your commits, as well as rebasing onto main instead of merging it in), and if you follow that, then force-pushing is by necessity a very common and normal operation. It isn't just for advanced users, and I find it important to spread the mindset that there's nothing scary about it.
I feel rather strongly that the current behavior should stay the default, and that a safer confirmation needs to be opt-in.
I think you're a git wizard.
But for us mortals that sometimes lose hours or days of work due to an accidental single keypress, usually taking even longer to emotionally recover, I would implore you to make the sacrifice of changing your config once so that those who come after us can be spared from this haunting mistake.
Also I assume you already have a config, us mortals only run default hoping that those are the safest and most beginner-friendly configuration possible.
is there any way to change force push's confirmation button instead of enter? I frequently got accidental force push because of this.
is there any way to change force push's confirmation button instead of enter? I frequently got accidental force push because of this.
Theoretically you should be able to remap "Confirm" from enter to something else (this then affects not only force-pushing, but all of lazygit's confirmation dialogs). However, this currently doesn't work, because that binding is also used for editable input fields (e.g. the new branch prompt). I'm working on fixing this, it will be possible in the next release.
There have been countless issues raised about force push over many years.
In Git: git push -f
In Lazygit: P → Enter
This shows a clear gap in the risk of accidental misuse. At the very least, please provide an option to confirm before doing a force push.
On both Mac and Linux, I don’t think there’s an idea of putting such a destructive action on the default Enter key. Pressing Enter in the default position is supposed to be a light, harmless action.
My 2c: I like the current default flow.
I started using lazygit recently and I generally love the fact the force push is a natural extension of a normal push. So you push, then it detects you need to force it, then you hit Enter. It's amazing, especially for my development workflows in which I rely on purely on rebase and amend constantly (instead of trillion small of commits like 'update' or 'now it works' etc).
I do think the comfort levels for force pushes might be different among users (e.g. those who don't feel comfortable rebasing) so an optional mode for different confirmation routines (captcha? joking ofc 🙃 ) or even blocking push on p and dedicating separate char e.g. F for it, might make sense.
Perhaps unrelated: I came on this issue to check if it's worth to solve the problem of accidental (non force) pushes to main branches locally (on lazygit). I did push accidentally on main recently, but I would totally do the same mistake in my previous UI (git gui). The proper fix for this (and for accidental force pushes) is likely to set up correct branching rules (at least on GitHub) for both force and non-force pushes.