cli: PR Create - GraphQL error due to wrong head branch detected

Describe the bug

When trying to create a Pull Request through gh pr create, I run into the following error:

pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and conftest-app-metrics, Head ref must be a branch
gh version 1.0.0 (2020-09-16)
https://github.com/cli/cli/releases/tag/v1.0.0

Steps to reproduce the behavior

  1. Fork a repo
  2. Clone and set origin and upstream
  3. Create a branch and commit some changes
  4. Run the following: gh pr create --fill

Expected vs actual behavior

I would have expected to see the PR created. Instead it results in the following error message.

pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and conftest-app-metrics, Head ref must be a branch

Logs

$ DEBUG=api gh pr create --fill                                                                     
[git remote -v]                                                  
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2020-09-18 16:23:58.899000113 -0600 MDT m=+0.032056143
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.antiope-preview+json
> Authorization: token 
> Content-Type: application/json; charset=utf-8
> User-Agent: GitHub CLI 1.0.0

{
    "query": "\n\tquery RepositoryInfo($owner: String!, $name: String!) {\n\t\trepository(owner: $owner, name: $name) {\n\t\t\tid\n\t\t\tname\n\t\t\towner { login }\n\t\t\thasIssuesEnabled\n\t\t\tdescription\n\t\t\tviewerPermission\n\t\t\tdefaultBranchRef {\n\t\t\t\tname\n\t\t\t}\n\t\t}\n\t}",
    "variables": {
        "name": "bitly",
        "owner": "bitly"
    }
}
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
< Cache-Control: no-cache
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Fri, 18 Sep 2020 22:24:36 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Status: 200 OK
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.antiope-preview; format=json
< X-Github-Request-Id: 
< X-Oauth-Client-Id: 
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4951
< X-Ratelimit-Reset: 1600469053
< X-Ratelimit-Used: 49
< X-Xss-Protection: 1; mode=block

{
    "data": {
        "repository": {
            "id": "MDEwOlJlcG9zaXRvcnkxNzYxMDE4",
            "name": "bitly",
            "owner": {
                "login": "bitly"
            },
            "hasIssuesEnabled": true,
            "description": "Bitly core repository",
            "viewerPermission": "WRITE",
            "defaultBranchRef": {
                "name": "master"
            }
        }
    }
}
* Request took 512.90788ms
[git symbolic-ref --quiet --short HEAD]
[git status --porcelain]
[git config --get-regexp ^branch\.conftest-app-metrics\.(remote|merge)$]
[git show-ref --verify -- HEAD refs/remotes/jharshman/conftest-app-metrics refs/remotes/origin/conftest-app-metrics refs/remotes/bitly/conftest-app-metrics refs/remotes/jharshman/conftest-app-metrics refs/remotes/mrwoof/conftest-app-metrics]
[git -c log.ShowSignature=false log --pretty=format:%H,%s --cherry origin/master...conftest-app-metrics]
* Request at 2020-09-18 16:23:59.506737366 -0600 MDT m=+0.639793409
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.antiope-preview+json
> Authorization: token 
> Content-Type: application/json; charset=utf-8
> User-Agent: GitHub CLI 1.0.0

{
    "query": "\n\tquery PullRequestForBranch($owner: String!, $repo: String!, $headRefName: String!) {\n\t\trepository(owner: $owner, name: $repo) {\n\t\t\tpullRequests(headRefName: $headRefName, states: OPEN, first: 30) {\n\t\t\t\tnodes {\n\t\t\t\t\tid\n\t\t\t\t\tnumber\n\t\t\t\t\ttitle\n\t\t\t\t\tstate\n\t\t\t\t\tbody\n\t\t\t\t\tmergeable\n\t\t\t\t\tauthor {\n\t\t\t\t\t\tlogin\n\t\t\t\t\t}\n\t\t\t\t\tcommits(last: 1) {\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t  nodes {\n\t\t\t\t\t\t  commit {\n\t\t\t\t\t\t\t  oid\n\t\t\t\t\t\t\t\tstatusCheckRollup {\n\t\t\t\t\t\t\t\t  contexts(last: 100) {\n\t\t\t\t\t\t\t\t    nodes {\n\t\t\t\t\t\t\t\t\t\t  ...on StatusContext {\n\t\t\t\t\t\t\t\t\t\t\t  context\n\t\t\t\t\t\t\t\t\t\t\t\tstate\n\t\t\t\t\t\t\t\t\t\t\t  targetUrl\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t...on CheckRun {\n\t\t\t\t\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\t\t\t\t\tstatus\n\t\t\t\t\t\t\t\t\t\t\t\tconclusion\n\t\t\t\t\t\t\t\t\t\t\t\tstartedAt\n\t\t\t\t\t\t\t\t\t\t\t\tcompletedAt\n\t\t\t\t\t\t\t\t\t\t\t\tdetailsUrl\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t  }\n\t\t\t\t\t}\n\t\t\t\t\turl\n\t\t\t\t\tbaseRefName\n\t\t\t\t\theadRefName\n\t\t\t\t\theadRepositoryOwner {\n\t\t\t\t\t\tlogin\n\t\t\t\t\t}\n\t\t\t\t\theadRepository {\n\t\t\t\t\t\tname\n\t\t\t\t\t}\n\t\t\t\t\tisCrossRepository\n\t\t\t\t\tisDraft\n\t\t\t\t\tmaintainerCanModify\n\t\t\t\t\treviewRequests(first: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\trequestedReviewer {\n\t\t\t\t\t\t\t\t__typename\n\t\t\t\t\t\t\t\t...on User {\n\t\t\t\t\t\t\t\t\tlogin\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t...on Team {\n\t\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\treviews(last: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\tauthor {\n\t\t\t\t\t\t\t  login\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tstate\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\tassignees(first: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\tlogin\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\tlabels(first: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\tprojectCards(first: 100) {\n\t\t\t\t\t\tnodes {\n\t\t\t\t\t\t\tproject {\n\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcolumn {\n\t\t\t\t\t\t\t\tname\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttotalCount\n\t\t\t\t\t}\n\t\t\t\t\tmilestone{\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}",
    "variables": {
        "headRefName": "conftest-app-metrics",
        "owner": "bitly",
        "repo": "bitly"
    }
}
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
< Cache-Control: no-cache
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Fri, 18 Sep 2020 22:24:36 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Status: 200 OK
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.antiope-preview; format=json
< X-Github-Request-Id:
< X-Oauth-Client-Id:
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4950
< X-Ratelimit-Reset: 1600469053
< X-Ratelimit-Used: 50
< X-Xss-Protection: 1; mode=block

{
    "data": {
        "repository": {
            "pullRequests": {
                "nodes": []
            }
        }
    }
}
* Request took 192.253972ms
* Request at 2020-09-18 16:23:59.699880362 -0600 MDT m=+0.832936377
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.antiope-preview+json
> Authorization: token 
> Content-Type: application/json; charset=utf-8
> User-Agent: GitHub CLI 1.0.0

{
    "query": "\n\t\tmutation PullRequestCreate($input: CreatePullRequestInput!) {\n\t\t\tcreatePullRequest(input: $input) {\n\t\t\t\tpullRequest {\n\t\t\t\t\tid\n\t\t\t\t\turl\n\t\t\t\t}\n\t\t\t}\n\t}",
    "variables": {
        "input": {
            "baseRefName": "master",
            "body": "",
            "draft": false,
            "headRefName": "conftest-app-metrics",
            "repositoryId": "MDEwOlJlcG9zaXRvcnkxNzYxMDE4",
            "title": "conftest app metrics"
        }
    }
}
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
< Cache-Control: no-cache
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Fri, 18 Sep 2020 22:24:36 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: GitHub.com
< Status: 200 OK
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< Vary: Accept-Encoding, Accept, X-Requested-With
< X-Accepted-Oauth-Scopes: repo
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-Github-Media-Type: github.antiope-preview; format=json
< X-Github-Request-Id: 
< X-Oauth-Client-Id: 
< X-Oauth-Scopes: gist, read:org, repo
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4949
< X-Ratelimit-Reset: 1600469053
< X-Ratelimit-Used: 51
< X-Xss-Protection: 1; mode=block

{
    "data": {
        "createPullRequest": {
            "pullRequest": null
        }
    },
    "errors": [
        {
            "type": "UNPROCESSABLE",
            "path": [
                "createPullRequest"
            ],
            "locations": [
                {
                    "line": 3,
                    "column": 4
                }
            ],
            "message": "Head sha can't be blank, Base sha can't be blank, No commits between master and conftest-app-metrics, Head ref must be a branch"
        }
    ]
}
* Request took 458.545525ms
pull request create failed: GraphQL error: Head sha can't be blank, Base sha can't be blank, No commits between master and conftest-app-metrics, Head ref must be a branch

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 10
  • Comments: 16 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@mislav I have the same issue when I try this from a github action worker. I commands I have used inside the worker are -

git checkout -b patch
git add .
git commit -m "adding data file"
gh pr create --title "Latest run Test Report" --body "Report Results" --head armsp:patch

Is this the correct way to make a PR from a local git branch to the remote master/main branch?

Currently using gh version 1.1.0 (2020-10-06) and I still experience this error.

Thank you everyone for your reports and patience! Currently fixed in trunk; we will cut a release soon 👍

@mislav I verified this issue in two ways. The first being allowing the cli to prompt me for which remote to push to, and the second being the way @a5anka described above. In both cases the fork was used and resulted in the same error message.

@cveneziani Please open another issue! Also include your git remote and branch setup in your report 🙇

I can confirm this issue. I too had fully pushed my branch to my fork via git push -f -u mvdan, yet gh pr create --fill would still fail like in the original post. I had to give it all the explicit flags to make it work: gh pr create --fill --base=master --head=mvdan:less-debugdir.