Skip to content

gh pr create --head doesn't properly handle forked workflow #10448

Open

Description

@jaymzh

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

  1. git checkout -b test upstream/main
  2. make a change and commit
  3. git push origin test
  4. gh 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

  1. added
    bug
    on Feb 14, 2025
  2. added
    needs-triage
    on Feb 14, 2025
  3. williammartin commented on Feb 17, 2025

    @williammartin
    Member

    Hey @jaymzh, just checking first, are the upstream and the fork in the same organization?

  4. added
    more-info-needed
    on Feb 17, 2025
  5. jaymzh commented on Feb 18, 2025

    @jaymzh
    Author

    @williammartin no, they're not in the same organization.

  6. williammartin commented on Feb 18, 2025

    @williammartin
    Member

    Right, looking more closely at your command:

    gh pr create --head origin/test --fill --base main
    

    I think the issue is that you're providing an unexpected format to --head and frankly, the help docs are not very useful. There is one example demonstrating the format for fork PRs:

    gh pr create --base develop --head monalisa:feature
    

    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:

    gh pr create --head <owner_containing_fork>:test --fill --base main
    

    If that's right, let me know and then we can work on improving the docs here.

  7. jaymzh commented on Feb 18, 2025

    @jaymzh
    Author

    That does in fact work! And works seemelessly when set for non-fork cases too. Thank you!

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

Metadata

Metadata

Assignees

Labels

bugmore-info-neededneeds-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions