Repository navigation
Description
Describe the bug
When the local and remote branch name doesn't match, there is no way for gh pr create --fill to work, whether I use the local or remote branch name. Both error in different ways.
Context: In our repo we use to call our development branches 'dev/myname/branchname'.
So we end up with a local branch called "foo" which matching remote is "dev/primiano/foo".
Example:
$ git checkout -b test
$ touch newfile
$ git add newfile && git commit -m 'test commit'
$ git push --set-upstream origin test:dev/primiano/test
Now I try to create the PR
$ gh pr create --head test --base main --fill
Creating pull request for test into main in google/perfetto
pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between main and test, Head ref must be a branch (createPullRequest)
if instead I pass the remote branch name in --head (Which I don't think it's the expected way it should be used), then --fill fails because it tries to log against the wrong branch name (dev/primiano/test which is the remote name, not the local one)
$ gh pr create --head dev/primiano/test --base main --fill
could not compute title or body defaults: failed to run git: fatal: ambiguous argument 'origin/main...dev/primiano/test': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
FYI:
$ git config --get-regexp '^branch\.test\.(remote|merge|pushremote|gh-merge-base)$'
branch.test.remote origin
branch.test.merge refs/heads/dev/primiano/test
Affected version
$ gh version
gh version 2.68.1 (2025-03-08)
https://github.com/cli/cli/releases/tag/v2.68.1
Steps to reproduce the behavior
See above
Expected vs actual behavior
gh pr create --head test --base main --fill should JustWork
Logs
Paste the activity from your command line. Redact if needed.
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Content-Length: 389
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: Europe/London
> User-Agent: GitHub CLI 2.68.1
GraphQL query:
fragment repo on Repository {
id
name
owner { login }
viewerPermission
defaultBranchRef {
name
}
isPrivate
}
query RepositoryNetwork {
viewer { login }
repo_000: repository(owner: "google", name: "perfetto") {
...repo
parent {
...repo
}
}
}
GraphQL variables: null
< HTTP/2.0 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-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Thu, 29 May 2025 15:58:37 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< 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.v4; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: 36E0:3B748E:990874:BCF107:6838842C
< X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
< X-Oauth-Scopes: gist, read:org, repo, workflow
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4926
< X-Ratelimit-Reset: 1748537013
< X-Ratelimit-Resource: graphql
< X-Ratelimit-Used: 74
< X-Xss-Protection: 0
{
"data": {
"viewer": {
"login": "primiano"
},
"repo_000": {
"id": "MDEwOlJlcG9zaXRvcnkyMjcwOTE1MDI=",
"name": "perfetto",
"owner": {
"login": "google"
},
"viewerPermission": "ADMIN",
"defaultBranchRef": {
"name": "main"
},
"isPrivate": false,
"parent": null
}
}
}
* Request took 345.699333ms
⣾* Request at 2025-05-29 16:58:37.369662 +0100 BST m=+1.222541459
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Content-Length: 570
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: Europe/London
> User-Agent: GitHub CLI 2.68.1
GraphQL query:
query PullRequestForBranch($owner: String!, $repo: String!, $headRefName: String!, $states: [PullRequestState!]) {
repository(owner: $owner, name: $repo) {
pullRequests(headRefName: $headRefName, states: $states, first: 30, orderBy: { field: CREATED_AT, direction: DESC }) {
nodes {url,id,number,state,baseRefName,headRefName,isCrossRepository,headRepositoryOwner{id,login,...on User{name}}}
}
defaultBranchRef { name }
}
}
GraphQL variables: {"headRefName":"test","owner":"google","repo":"perfetto","states":["OPEN"]}
⣻< HTTP/2.0 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-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Thu, 29 May 2025 15:58:37 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< 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.v4; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: 36E0:3B748E:9908A0:BCF140:6838842D
< X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
< X-Oauth-Scopes: gist, read:org, repo, workflow
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4925
< X-Ratelimit-Reset: 1748537013
< X-Ratelimit-Resource: graphql
< X-Ratelimit-Used: 75
< X-Xss-Protection: 0
{
"data": {
"repository": {
"pullRequests": {
"nodes": []
},
"defaultBranchRef": {
"name": "main"
}
}
}
}
* Request took 274.588ms
Creating pull request for test into main in google/perfetto
⣾* Request at 2025-05-29 16:58:37.669124 +0100 BST m=+1.522003501
* Request to https://api.github.com/graphql
> POST /graphql HTTP/1.1
> Host: api.github.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Content-Length: 450
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: Europe/London
> User-Agent: GitHub CLI 2.68.1
GraphQL query:
mutation PullRequestCreate($input: CreatePullRequestInput!) {
createPullRequest(input: $input) {
pullRequest {
id
url
}
}
}
GraphQL variables: {"input":{"baseRefName":"main","body":"- **tools/git_sync_stack use remote branch name**\n- **test commit**\n","draft":false,"headRefName":"test","maintainerCanModify":true,"repositoryId":"MDEwOlJlcG9zaXRvcnkyMjcwOTE1MDI=","title":"test"}}
⢿< HTTP/2.0 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-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
< Content-Security-Policy: default-src 'none'
< Content-Type: application/json; charset=utf-8
< Date: Thu, 29 May 2025 15:58:38 GMT
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Server: github.com
< 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.v4; param=merge-info-preview.nebula-preview; format=json
< X-Github-Request-Id: 36E0:3B748E:9908CB:BCF170:6838842D
< X-Oauth-Client-Id: 178c6fc778ccc68e1d6a
< X-Oauth-Scopes: gist, read:org, repo, workflow
< X-Ratelimit-Limit: 5000
< X-Ratelimit-Remaining: 4924
< X-Ratelimit-Reset: 1748537013
< X-Ratelimit-Resource: graphql
< X-Ratelimit-Used: 76
< X-Xss-Protection: 0
{
"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 main and test, Head ref must be a branch"
}
],
"extensions": {
"warnings": [
{
"type": "DEPRECATION",
"message": "The id MDEwOlJlcG9zaXRvcnkyMjcwOTE1MDI= is deprecated. Update your cache to use the next_global_id from the data payload.",
"data": {
"legacy_global_id": "MDEwOlJlcG9zaXRvcnkyMjcwOTE1MDI=",
"next_global_id": "R_kgDODYkkLg"
},
"link": "https://docs.github.com"
}
]
}
}
* Request took 458.685583ms
pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between main and test, Head ref must be a branch (createPullRequest)
Activity
BagToad commentedon May 29, 2025
👋 Hey @primiano, thanks for filling this out! ✨
Could you please try upgrading to the latest version? We recently completed a large body of work to the
prcommands for detecting refs starting inv2.71.0.I haven't dug into the problem exactly yet because I want to understand the behavior in the latest version, but at face value it sounds like what you're seeing is expected for versions older than
v2.71.0.primiano commentedon May 29, 2025
I just tried 2.73.0 and exhibits the same problem
BagToad commentedon May 29, 2025
Thanks for trying. Could you drop the debug output for the latest version? We do much different logic in that version so I want to follow it through to see what's up.
primiano commentedon May 29, 2025
BagToad commentedon May 29, 2025
Thanks @primiano 🙇
Can you try it without the
-H test -B mainoptions please?primiano commentedon May 29, 2025
Oh if I don't pass -H test it works fine (even if the local and remote branch name don't match), I tried that before.
But that doesn't work for use.
We use use -H and -B in script as often we deal with a stack of branches (one PR per branch, PR1 based on main, PR2 based on PR1, PR3 based on PR2). I'd like to run a command to upload them all without having to checkout each branch individually.
Fix `pr create --fill` when local branch name differs from remote