git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Can I avoid typing so much when --force-with-lease, --force-if-includes, detached HEAD, and no local branch?

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
May 8, 2025, 16:09 UTC
Message-ID
<CALnO6CCk0SgwObQRnpd5Pt_DvCKF8dBmyVHivU6Nr_O-GusGLA@mail.gmail.com>

I'm trying to understand some confusing behavior with the interaction of the situations mentioned in the subject line—in particular, I'm trying to figure out if this is expected behavior and what I can do to ease my own pain when I occasionally have reason for the following workflow:

- Colleague pushes a branch; it needs some help to get merged, which
they don't have time for. I do.
- After "git fetch," since the cleanups are small, I "git switch
--detach origin/their-branch"
- Hack hack; "git commit --amend" or some other history-rewriting
command (e.g., also "git rebase origin" while I'm at it)
- (after copying the range-diff) "git pf origin @:refs/heads/their-branch"

Now, "pf" is an alias for "push --force --force-with-lease" (what I think of as "safer force push"), and I have "push.useForceIfIncludes = true" set globally.

I'm _expecting_ Git to push, since the remote-tracking branch I'd be updating hasn't changed. Instead, I get a "remote ref updated since checkout" rejection complete with advice about the tip having changed. But the tip hasn't actually changed, which I'm able to verify in several ways.

While writing this mail, it occurred to me that maybe the issue is that the reflog behavior from --force-if-includes doesn't work in detached HEAD mode? At any rate, doing "git pf --force-with-lease=their-branch:$(git rev-parse origin/their-branch) origin @:refs/heads/their-branch" works, but omitting the right-hand-side of the lease doesn't.

Should I stop using force-if-includes when in detached HEAD (aka, start passing "--no-force-if-includes" in those rare circumstances)? Or is there a shorter way to get where I want to go here?

-- 
D. Ben Knoble
Message 1 of 1 in “Can I avoid typing so much when --force-with-lease, --force-if-includes, detached HEAD, and no local branch?”
  1. D. Ben KnobleMay 8, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.