Skip to content

gh pr create: improve validation and error messaging for invalid ref inputs #12889

Open

Description

@BagToad

Problem

When gh pr create sends invalid ref data to the GitHub GraphQL API, the raw error message surfaces directly to the user:

pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank,
No commits between main and <branch>, Head ref must be a branch, Base ref must be a branch

This message is unhelpful because it describes internal API validation failures, not what the user did wrong or how to fix it. There are many different ways users end up here, including:

In all of these cases, the user sees the same opaque GraphQL error.

Proposed solution

Add some sort of client-side state validation before the createPullRequest mutation is sent, with actionable error messages.

Maybe:

  • If headRefName contains a / that matches a known remote name, suggest using owner:branch syntax instead
  • If baseRefName resolves to a SHA instead of a branch name, tell the user to pass just the branch name
  • If the head branch doesn't appear to be pushed to any GitHub remote, say so explicitly and suggest pushing first
  • If the mutation fails, wrap the GraphQL error with context about what was sent and common fixes

Goal

Make it easier to understand what might be wrong with the user's input when gh pr create fails.

Related issues

Issue Summary
#2691 Skip-push fails when @{upstream} != push remote (33 👍)
#1645 Respect git @{push} config (5 👍)
#6462 Can't work with same-org forked repos (3 👍)
#12824 Fails with multiple remotes (remote-prefixed refs)
#11970 --head doesn't push
#11041 Assumes local and remote branch names match
#10448 --head doesn't handle forked workflow
#10238 Mysterious "no commits between" message
#9201 --dry-run works but actual command does not
#6224 "PR creation fails with a very confusing message"
#6864 Preserve user inputs more defensively (recovery/data loss)

Activity

  1. added
    enhancement
    gh-pr
    on Mar 9, 2026
  2. added
    needs-triage
    on Mar 9, 2026
  3. github-actions commented on Mar 9, 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.

  4. removed
    needs-triage
    on Mar 9, 2026
  5. added
    core
    tech-debt
    on Mar 9, 2026
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

    coreenhancementgh-prstaletech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions