Hello, On 09/14/2020 13:17, Junio C Hamano wrote: > Srinidhi Kaushik <shrinidhi.kaushik@xxxxxxxxx> writes: > > > Add a check to verify if the remote-tracking ref of the local branch is > > reachable from one of its "reflog" entries; `set_ref_status_for_push` > > updated to add a reject reason and disallow the forced push if the > > check fails. > > I have to wonder (not objecting to, just wondering about) if it is a > good assumption that the current branch must be where we should have > seen the tip of the other side we are about to lose. I ask because > when I do a large rewrite I often am on a detached HEAD most of the > time, and after everything looks sensible in the rewritten result, > I "checkout -B" the local branch. > > We could reduce the rate of false positive ("no you've not looked at > what you are about to discard, so we won't let you force") by > checking reflogs of all the local branches and HEAD, but that may be > too much. I wonder if checking reflog entries only for HEAD (and > not any of the current local branches) would be a good compromise. One scenario I can think of is when there are multiple local branches that track the same remote. Let's say we have two branches "A" and "B" and they both track "A" on the remote. If we are currently on "A", and then we decide to rebase on "origin/A" (after a push from another repository). Then, if we (accidentally) switch to "B", and force update with `--force-if-includes` it will _not_ be rejected because HEAD's reflog has a record of the checkout and there will be an overwrite if we check only HEAD's reflog. Thanks. -- Srinidhi Kaushik