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

[PATCH v7 0/3] push: check pushed ref for --force-if-includes

From
Tyler Cipriani <tyler@tylercipriani.com>
Date
Oct 18, 2026, 20:32 UTC
Message-ID
<20261018203255.2343005-1-tyler@tylercipriani.com>
In-Reply-To
<20260904210122.431757-1-tyler@tylercipriani.com>

--force-if-includes is meant to refuse a forced push unless the tip of the remote-tracking ref has been integrated into the ref you're pushing. But it checks the reflog of the local branch named after the destination, regardless of the ref being pushed.

For example, this command consults the reflog of main instead of src:
    git push --force-with-lease --force-if-includes origin src:main
Checking the wrong ref causes two problems:
- Data loss: if the local main has integrated origin/main, then the
  check passes even when src is an unrelated or outdated branch,
  allowing a push that clobbers the remote main.
- False rejections: if src has integrated origin/main but the local
  main is behind or missing, the push is rejected with "remote ref
  updated since checkout". Stefan Haller[0] and D. Ben Knoble[1] have
  both reported this.

1/3 checks the reflog of the branch that the pushed ref resolves to. 2/3 gives pushes that cannot be checked their own rejection status and advice. 3/3 fixes an existing bug: --force-if-includes runs its reflog check before the fast-forward rules, so it can reject a push that needs no force at all, e.g., when the reflog has expired. 1/3 makes this worse, since every push of a non-branch ref now fails the reflog check.

Behavior change ---------------

Only a branch's reflog records whether the remote tip was integrated into it, so --force-if-includes can only verify a source that resolves to a branch. HEAD's reflog spans all branches, and was rejected as too broad in the original review[2]. A tag's reflog, when it exists, records where the tag pointed. Mapping an oid to "the branch that points at it" is ambiguous, since many branches can point at the same commit.

So a forced push whose source does not resolve to a branch (a detached HEAD, a tag, an oid) is now rejected as unverifiable. The advice suggests naming the expected value with --force-with-lease=<ref>:<expect>, or skipping the check with --no-force-if-includes.

This breaks workflows that only appear to work today. For example, this passes today if a local "hotfix" branch has integrated origin/hotfix, even though nothing about <tag> is checked:

    git push --force-with-lease --force-if-includes origin <tag>:hotfix

Fast-forward pushes of non-branch refs are still allowed (3/3), since a fast-forward shows the remote tip has been integrated.

I'd welcome opinions on this trade-off.
Changes since v6:
- 1/3: fix a doubled "for" and the spelling of
  check_if_includes_upstream in the log message.
- 3/3: add missing "()" to function name in log message.
- Rebase on maint at v2.56.0, resolving conflicts with a85a43c480
  (push: suggest <remote> <branch> for a slash slip, 2026-06-27). The
  advice changes in the 2/3 range-diff are context from the
  pushRepoLooksLikeRef advice added there.
- The textual conflict in t5533 with as/push-force-if-includes-no-reflog
  remains: both topics add tests after the same existing test.
Earlier changes are listed in the v6 cover letter[3].
The new tests fail on maint and pass with this series applied.

[0]: <https://lore.kernel.org/git/f51c73ed-eb03-83ca-fb31-d3e2645c9a63@haller-berlin.de> [1]: <https://lore.kernel.org/git/CALnO6CCk0SgwObQRnpd5Pt_DvCKF8dBmyVHivU6Nr_O-GusGLA@mail.gmail.com> [2]: <https://lore.kernel.org/git/xmqqsgbdk69b.fsf@gitster.c.googlers.com/> [3]: <https://lore.kernel.org/git/20260917224351.57171-1-tyler@tylercipriani.com/>

Tyler Cipriani (3):
  push: check pushed ref for --force-if-includes
  push: fix --force-if-includes non-branch advice
  push: --force-if-includes should allow fast-forward
 Documentation/config/advice.adoc |   4 ++
 advice.c                         |   1 +
 advice.h                         |   1 +
 builtin/push.c                   |  17 +++++
 builtin/send-pack.c              |   5 ++
 remote.c                         |  43 ++++++++++--
 remote.h                         |  10 ++-
 send-pack.c                      |   1 +
 t/t5533-push-cas.sh              | 115 ++++++++++++++++++++++++++++++-
 transport-helper.c               |   5 ++
 transport.c                      |   8 +++
 transport.h                      |   1 +
 12 files changed, 203 insertions(+), 8 deletions(-)
Range-diff against v6:
1:  e7912c3fd0 ! 1:  959490bb0a push: check pushed ref for --force-if-includes
    @@ Commit message
         The early return when peer_ref is missing in check_if_includes_upstream
         is necessary because apply_push_cas walks every advertised ref whenever
         use_tracking_for_rest is set (i.e., a bare --force-with-lease), so
    -    check_if_includes upstream is called for for refs that are not part of
    -    the push.
    +    check_if_includes upstream is called for refs that are not part of the
    +    push.
     
         Remove unnecessary check for empty return from get_local_ref, since it
         never returns NULL for a non-empty name.
2:  f85041efa8 ! 2:  92ef5412e1 push: fix --force-if-includes non-branch advice
    @@ Documentation/config/advice.adoc: all advice messages.
     +		Shown when linkgit:git-push[1] rejects a forced update of
     +		a branch when we are unable to verify the remote-tracking
     +		ref is integrated locally.
    - 	pushUnqualifiedRefname::
    - 		Shown when linkgit:git-push[1] gives up trying to
    - 		guess based on the source and destination refs what
    + 	pushRepoLooksLikeRef::
    + 		Shown when the repository given to linkgit:git-push[1] is not
    + 		a configured remote but looks like a `<remote>/<branch>` ref,
     
      ## advice.c ##
     @@ advice.c: static struct {
    @@ advice.c: static struct {
      	[ADVICE_PUSH_NON_FF_MATCHING]			= { "pushNonFFMatching" },
      	[ADVICE_PUSH_REF_NEEDS_UPDATE]			= { "pushRefNeedsUpdate" },
     +	[ADVICE_PUSH_REF_UNVERIFIABLE]			= { "pushRefUnverifiable" },
    + 	[ADVICE_PUSH_REPO_LOOKS_LIKE_REF]		= { "pushRepoLooksLikeRef" },
      	[ADVICE_PUSH_UNQUALIFIED_REF_NAME]		= { "pushUnqualifiedRefName" },
      	[ADVICE_PUSH_UPDATE_REJECTED]			= { "pushUpdateRejected" },
    - 	[ADVICE_PUSH_UPDATE_REJECTED_ALIAS]		= { "pushNonFastForward" }, /* backwards compatibility */
     
      ## advice.h ##
     @@ advice.h: enum advice_type {
    @@ advice.h: enum advice_type {
      	ADVICE_PUSH_NON_FF_MATCHING,
      	ADVICE_PUSH_REF_NEEDS_UPDATE,
     +	ADVICE_PUSH_REF_UNVERIFIABLE,
    + 	ADVICE_PUSH_REPO_LOOKS_LIKE_REF,
      	ADVICE_PUSH_UNQUALIFIED_REF_NAME,
      	ADVICE_PUSH_UPDATE_REJECTED,
    - 	ADVICE_PUSH_UPDATE_REJECTED_ALIAS,
     
      ## builtin/push.c ##
     @@ builtin/push.c: static const char message_advice_ref_needs_update[] =
3:  f9d97b0644 ! 3:  f97092092d push: --force-if-includes should allow fast-forward
    @@ Metadata
      ## Commit message ##
         push: --force-if-includes should allow fast-forward
     
    -    In set_ref_status_for_push, we apply --force-if-includes's reflog
    +    In set_ref_status_for_push(), we apply --force-if-includes's reflog
         reachability checks before fast-forward rules. As a result, valid
         fast-forward pushes may be rejected when a force push is unneeded; like
         when the reflog is expired:
-- 
2.47.3
Previous: Tyler CiprianiNext: Tyler Cipriani
Message 41 of 44 in “push: fix --force-if-includes consulting wrong ref”
  1. 0/2 push: fix --force-if-includes consulting wrong refTyler Cipriani, Sep 4, 2026
  2. 1/2 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 4, 2026
  3. Ben KnobleSep 5, 2026
  4. 2/2 push: fix --force-if-includes detached HEAD adviceTyler Cipriani, Sep 4, 2026
  5. Ben KnobleSep 5, 2026
  6. Tyler CiprianiSep 6, 2026
  7. 0/2 push: fix --force-if-includes consulting wrong refTyler Cipriani, Sep 8, 2026
  8. D. Ben KnobleSep 9, 2026
  9. 1/2 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 8, 2026
  10. Junio C HamanoSep 10, 2026
  11. Tyler CiprianiSep 10, 2026
  12. 2/2 push: fix --force-if-includes detached HEAD adviceTyler Cipriani, Sep 8, 2026
  13. 0/2 push: fix --force-if-includes consulting wrong refTyler Cipriani, Sep 10, 2026
  14. 1/2 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 10, 2026
  15. Patrick SteinhardtSep 11, 2026
  16. Tyler CiprianiSep 11, 2026
  17. Junio C HamanoSep 11, 2026
  18. Tyler CiprianiSep 11, 2026
  19. 2/2 push: fix --force-if-includes detached HEAD adviceTyler Cipriani, Sep 10, 2026
  20. Patrick SteinhardtSep 11, 2026
  21. Junio C HamanoSep 11, 2026
  22. Junio C HamanoSep 11, 2026
  23. 0/2 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 14, 2026
  24. 1/2 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 14, 2026
  25. 2/2 push: fix --force-if-includes non-branch adviceTyler Cipriani, Sep 14, 2026
  26. D. Ben KnobleSep 14, 2026
  27. Tyler CiprianiSep 14, 2026
  28. D. Ben KnobleSep 14, 2026
  29. 0/3 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 15, 2026
  30. 1/3 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 15, 2026
  31. 2/3 push: fix --force-if-includes non-branch adviceTyler Cipriani, Sep 15, 2026
  32. 3/3 push: --force-if-includes should allow fast-forwardTyler Cipriani, Sep 15, 2026
  33. D. Ben KnobleSep 16, 2026
  34. Tyler CiprianiSep 16, 2026
  35. Ben KnobleSep 16, 2026
  36. 0/3 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 17, 2026
  37. 1/3 push: check pushed ref for --force-if-includesTyler Cipriani, Sep 17, 2026
  38. 2/3 push: fix --force-if-includes non-branch adviceTyler Cipriani, Sep 17, 2026
  39. 3/3 push: --force-if-includes should allow fast-forwardTyler Cipriani, Sep 17, 2026
  40. Tyler CiprianiOct 5, 2026
  41. 0/3 push: check pushed ref for --force-if-includesTyler Cipriani, Oct 18, 2026
  42. 1/3 push: check pushed ref for --force-if-includesTyler Cipriani, Oct 18, 2026
  43. 2/3 push: fix --force-if-includes non-branch adviceTyler Cipriani, Oct 18, 2026
  44. 3/3 push: --force-if-includes should allow fast-forwardTyler Cipriani, Oct 18, 2026

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.