{"thread":{"id":"63422","subject":"Can I avoid typing so much when --force-with-lease, --force-if-includes, detached HEAD, and no local branch?","startedAt":"2025-05-08T16:10:16Z","lastAt":"2025-05-08T16:10:16Z","messageCount":1,"participants":["D. Ben Knoble"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"517570","messageId":"CALnO6CCk0SgwObQRnpd5Pt_DvCKF8dBmyVHivU6Nr_O-GusGLA@mail.gmail.com","threadId":"63422","inReplyTo":null,"subject":"Can I avoid typing so much when --force-with-lease, --force-if-includes, detached HEAD, and no local branch?","fromName":"D. Ben Knoble","fromEmail":"ben.knoble@gmail.com","sentAt":"2025-05-08T16:09:51Z","receivedAt":"2025-05-08T16:10:16Z","isPatch":false,"sender":{"key":"ben.knoble@gmail.com","avatar":"https://avatars.githubusercontent.com/u/22802209?v=4"},"body":"I'm trying to understand some confusing behavior with the interaction\nof the situations mentioned in the subject line—in particular, I'm\ntrying to figure out if this is expected behavior and what I can do to\nease my own pain when I occasionally have reason for the following\nworkflow:\n\n- Colleague pushes a branch; it needs some help to get merged, which\nthey don't have time for. I do.\n- After \"git fetch,\" since the cleanups are small, I \"git switch\n--detach origin/their-branch\"\n- Hack hack; \"git commit --amend\" or some other history-rewriting\ncommand (e.g., also \"git rebase origin\" while I'm at it)\n- (after copying the range-diff) \"git pf origin @:refs/heads/their-branch\"\n\nNow, \"pf\" is an alias for \"push --force --force-with-lease\" (what I\nthink of as \"safer force push\"), and I have \"push.useForceIfIncludes =\ntrue\" set globally.\n\nI'm _expecting_ Git to push, since the remote-tracking branch I'd be\nupdating hasn't changed. Instead, I get a \"remote ref updated since\ncheckout\" rejection complete with advice about the tip having changed.\nBut the tip hasn't actually changed, which I'm able to verify in\nseveral ways.\n\nWhile writing this mail, it occurred to me that maybe the issue is\nthat the reflog behavior from --force-if-includes doesn't work in\ndetached HEAD mode? At any rate, doing \"git pf\n--force-with-lease=their-branch:$(git rev-parse origin/their-branch)\norigin @:refs/heads/their-branch\" works, but omitting the\nright-hand-side of the lease doesn't.\n\nShould I stop using force-if-includes when in detached HEAD (aka,\nstart passing \"--no-force-if-includes\" in those rare circumstances)?\nOr is there a shorter way to get where I want to go here?\n\n-- \nD. Ben Knoble\n"}]}