Repository navigation
Description
Describe the bug
Given two remotes: upstream and origin, if I create a branch which I'd like to track upstream/main:
git checkout -b test upstream/main
make some changes, push it to my origin:
git push origin test
and try to make a pr where I tell gh that I don't want it to push or prompt me for where to push it:
gh pr create --head origin/test --fill --base main
It will fail:
Creating pull request for origin/test into main in facebook/chef-cookbooks
pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between main and origin/test, Head ref must be a branch (createPullRequest)
However, you can see there are in fact differences:
$ git diff 'upstream/main...origin/test'
diff --git a/chefignore b/chefignore
index f2d147e..de70a57 100644
--- a/chefignore
+++ b/chefignore
@@ -129,3 +129,5 @@ Strainerfile
###########
.vagrant
Vagrantfile
+
+# test
This same result happens if you do just do gh pr create and then choose "skip pushing".
You may ask "why bypass pushing" - for many reasons, but one of them is that I don't want it setting the upstream tracking branch to origin/test, because I'm actually tracking upstream/main. Another is that I don't want prompts since I'm wrapping this from another tool.
There's no other way to prevent pushing, based on the help docks, except to specify this with --head, as far as I can tell.
Affected version
gh version 2.67.0 (2025-02-11)
https://github.com/cli/cli/releases/tag/v2.67.0
Steps to reproduce the behavior
git checkout -b test upstream/main- make a change and commit
git push origin testgh pr create --head origin/test --fill --base main
Expected vs actual behavior
Expected: It to see I've pushed and not try to push and not change my tracking branch.
Actual: get error above
Logs
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2025-02-14 15:18:27.957603187 -0800 PST m=+0.051514670
* Request to https://api.github.com/graphql
* Request took 313.151761ms
[git status --porcelain]
[git config --get-regexp ^branch\.origin/test\.(remote|merge|pushremote|gh-merge-base)$]
[git -c log.ShowSignature=false log --pretty=format:%H%x00%s%x00%b%x00 --cherry upstream/main...origin/test]
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2025-02-14 15:18:28.286511145 -0800 PST m=+0.380422638
* Request to https://api.github.com/graphql
⣻* Request took 256.066983ms
Creating pull request for origin/test into main in facebook/chef-cookbooks
* Request at 2025-02-14 15:18:28.543131734 -0800 PST m=+0.637043217
* Request to https://api.github.com/graphql
⣻* Request took 335.883886ms
pull request create failed: GraphQL: Head sha can't be blank, Base sha can't be blank, No commits between main and origin/test, Head ref must be a branch (createPullRequest)
Activity
williammartin commentedon Feb 17, 2025
Hey @jaymzh, just checking first, are the upstream and the fork in the same organization?
jaymzh commentedon Feb 18, 2025
@williammartin no, they're not in the same organization.
williammartin commentedon Feb 18, 2025
Right, looking more closely at your command:
I think the issue is that you're providing an unexpected format to
--headand frankly, the help docs are not very useful. There is one example demonstrating the format for fork PRs:This
:syntax is something that the GitHub API understands to indicate "look for a branch of name "feature", from a fork in owner "monalisa".So I would anticipate that your command would look like:
If that's right, let me know and then we can work on improving the docs here.
jaymzh commentedon Feb 18, 2025
That does in fact work! And works seemelessly when set for non-fork cases too. Thank you!