Skip to content

gh pr merge refuses when ruleset bypass authority would resolve the block #13388

Open

Description

@dadcoachengineer

Description

When the calling user has ruleset bypass authority that would resolve a mergeStateStatus: BLOCKED PR (e.g., via bypass_actors with bypass_mode: pull_request matching the user's RepositoryRole), gh pr merge refuses at pre-flight rather than attempting the merge. The error offers --admin
or --auto as escape hatches, neither of which fits what the user actually needs.

The underlying REST API merge endpoint (PUT /repos/{owner}/{repo}/pulls/{n}/merge) does engage bypass correctly when called directly. So the gap
is in gh pr merge's pre-flight logic, not in the API.

For repositories using rulesets with bypass_actors as a deliberate design choice — codifying who can self-merge per design intent rather than via
admin override — this means every PR by a bypass-eligible user falls back to --admin. Bypass becomes configured-but-unused; admin overrides
accumulate as if the rule were misconfigured.

Reproduction

  1. Configure a ruleset on main with required_approving_review_count: 1 and:

    "bypass_actors": [
      {
        "actor_id": 5,
        "actor_type": "RepositoryRole",
        "bypass_mode": "pull_request"
      }
    ]
    
  2. As the bypass-eligible user (here, a repo admin — RepositoryRole=5), open a PR. The PR will have:
    - mergeStateStatus: BLOCKED
    - reviewDecision: REVIEW_REQUIRED
    - reviewCount: 0

  3. Confirm bypass eligibility — GET /repos/{owner}/{repo}/rulesets/{id} returns:

"current_user_can_bypass": "pull_requests_only"
4. Try gh pr merge:

$ gh pr merge <PR#> --squash --delete-branch
X Pull request /#<PR#> is not mergeable: the base branch policy prohibits the merge.
To have the pull request merged after all the requirements have been met, add the --auto flag.
To use administrator privileges to immediately merge the pull request, add the --admin flag.
5. Call the REST merge endpoint directly — succeeds, bypass engages:

$ gh api repos///pulls/<PR#>/merge -X PUT -f merge_method=squash
{"sha":"...","merged":true,"message":"Pull Request successfully merged"}

Expected behavior

gh pr merge should detect bypass eligibility before refusing. Two reasonable fix shapes:

  • Conservative: if mergeStateStatus: BLOCKED but current_user_can_bypass indicates bypass-via-pull_request, attempt the merge — the API will engage
    bypass automatically.
  • Simpler: always attempt the API merge and let GitHub's response be authoritative. Bypass engages or it doesn't, and either way the API's response is
    meaningful (success, or a real error worth surfacing). The current pre-flight refusal pre-empts an outcome the API would have produced correctly.

Actual behavior

gh pr merge refuses based purely on mergeStateStatus: BLOCKED without checking bypass authority. Suggested escape hatches:

  • --admin works but is structurally the wrong fit — admin override loudly overrides a rule that the user is in fact authorized to bypass per design.
  • --auto doesn't engage bypass either; auto-merge waits for the original blockers to resolve, which (with bypass authority) won't happen organically.

gh version

gh version 2.90.0 (2026-04-16)

Why this matters

Rulesets with bypass_actors are a natural way to encode "who can self-merge" per design intent for repos with mixed-author models (e.g., bot-authored
PRs requiring review; human-authored PRs not). When gh pr merge doesn't respect bypass, the design becomes ceremony that doesn't deliver: operators
fall back to --admin per PR, repeated admin override erodes the rule's authority, and the codified bypass goes unused.

Current workaround: shell wrapper around gh api .../pulls/{n}/merge -X PUT. Functional but loses the ergonomic value of gh pr merge (mergeStateStatus
visibility, branch deletion semantics, default merge method from repo settings, etc.).

Upstream context

Activity

  1. added
    needs-triage
    on May 9, 2026
  2. babakks commented on May 15, 2026

    @babakks
    Member

    Thanks for the detailed write-up, @dadcoachengineer! 🙏

    I looked into this and agree there's a gap here, though I see it as a missing feature rather than a bug in the existing preflight logic. Here's my thinking:

    When a PR has mergeStateStatus: BLOCKED, I think it's correct for gh pr merge to refuse by default. Even on the web UI, bypassing ruleset protections requires an explicit action (the "bypass rules" checkbox). I'd want the CLI to follow the same pattern rather than silently bypassing rules.

    It's worth noting that --admin is purely a client-side confirmation, similar to the checkbox on the web UI. It doesn't send anything special to the API or merge with elevated permissions. It just tells gh to skip its own preflight check and let the server decide whether the caller actually has the authority to merge. So in practice, --admin already works for your use case. That said, I understand it feels like the wrong tool for the job when you're exercising ruleset bypass authority rather than admin override.

    I see this report as an opportunity to improve things on two fronts: first, better UX by offering a separate, less confusing flag for ruleset bypass; and second, keeping merge queue behavior distinct from other rulesets. Although merge queues are technically enforced via rulesets, gh pr merge already treats them as a separate concern, and I think that separation is worth preserving.

    What I'm considering is a new --bypass-rules flag that would:

    • Skip the BLOCKED preflight check (similar to how --admin works today)
    • Let the API determine whether the caller actually has bypass authority, and surface the server's response either way
    • Still respect merge queues if one is configured (unlike --admin, which bypasses both rulesets and the merge queue)

    This would give bypass-eligible users a clear, intentional way to merge without reaching for --admin, which carries broader semantics (it also skips the merge queue entirely and performs a direct merge).

    I'll label this as an enhancement and keep it open for tracking. No timeline to share right now, but I appreciate you laying out the problem so clearly.

  3. added
    enhancement
    gh-pr
    on May 15, 2026
  4. github-actions commented on May 15, 2026

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as an enhancement (feature or improvement) request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Contributions welcome label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

  5. removed
    needs-triage
    on May 15, 2026
  6. babakks commented on May 15, 2026

    @babakks
    Member

    Here are my suggested changes for the new --bypass-rules flag. Note that both --admin and --bypass-rules are purely client-side overrides and there's no API-level concept/input for them.

    1. New --bypass-rules flag, off by default.

    2. Flag docs: "Bypass branch rulesets to merge a pull request, except merge queue constraints"

      For context on how pr merge handles merge queues today: when a branch has a merge queue enabled, pr merge skips the BLOCKED/BEHIND preflight entirely. If required checks have passed, the PR is added to the queue; if not, auto-merge is enabled. The --bypass-rules flag does not change this behavior.

    3. Update --admin flag docs from the current: "Use administrator privileges to merge a pull request that does not meet requirements", to something like: "Bypass branch rulesets to merge a pull request, including merge queue constraints"

    4. --bypass-rules is mutually exclusive with --admin, --auto, and --disable-auto (same as --admin is today).

    5. Update the preflight error message (currently shown when mergeStateStatus is BLOCKED) to mention --bypass-rules as an option alongside --admin. Differentiate the two hints:

      • --bypass-rules: for users with ruleset bypass authority.
      • --admin: for admins; also bypasses merge queue constraints.
    6. When --bypass-rules is used on a queue-enabled repo, it is effectively a no-op (the queue path already skips the BLOCKED preflight). No error, no special handling needed.

    Please share your thoughts, @BagToad and @williammartin, so that we can put down the A/C for this change.

  7. added
    pitch
    on May 21, 2026
  8. jgsuess commented on Jul 23, 2026

    @jgsuess

    +1, hitting this too. We're running Dependabot auto-merge via gh pr merge --auto --squash from a GitHub App identity that is a configured bypass_actors entry on a repository ruleset requiring code owner review. The client-side mergeability pre-check refuses the merge even though the underlying REST PUT /pulls/{n}/merge endpoint honors the bypass and merges immediately when called directly. This is currently blocking essential Dependabot automation across multiple repos for us — would really appreciate a fix or at least an official workaround/flag to skip the client-side check for bypass-eligible actors.

  9. jgsuess commented on Jul 23, 2026

    @jgsuess

    Follow-up: worth distinguishing two related-but-separate bugs here, since I've now also filed detailed repro on the platform side. This CLI issue is about gh pr merge's client-side mergeStateStatus pre-check refusing to attempt a merge for a bypass-eligible actor. Separately, there's a deeper platform bug where even GitHub's own async auto-merge completion (via enablePullRequestAutoMerge, not just gh) never re-checks bypass_actors when it finally executes the merge — confirmed via a clean 10-minute unattended test, with a direct synchronous PUT .../merge call succeeding instantly on the same PR. Details and repro steps posted at https://github.com/orgs/community/discussions/162623 and https://github.com/orgs/community/discussions/190610 in case that's useful context for whoever picks this up.

  10. keapa22 commented on Nov 12, 2026

    @keapa22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgh-prpitch

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions