cli: `pr checkout` assumes wrong git remote as the base repository

$ ~/Downloads/gh_0.5.4_macOS_amd64/bin/gh --version
gh version 0.5.4 (2020-02-04)
https://github.com/cli/cli/releases/tag/v0.5.4

Steps to reproduce the behavior

From my clone of the sympy/sympy repo I tried to clone PR 18646

$ ~/Downloads/gh_0.5.4_macOS_amd64/bin/gh pr checkout 18646
graphql error: 'Could not resolve to a PullRequest with the number of 18646.'

About this issue

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

Most upvoted comments

@PowerKiKi Since jbox-web/redmine_git_hosting is a fork, gh pr checkout 123 in that repo will try to check out PR #123 of the parent repository. This might not be what you wanted.

We might change this default, but until then, the only workaround you can do is:

gh pr checkout -R jbox-web/redmine_git_hosting 123

gh should not assume the “upstream” style of remote management. I personally think the “origin is upstream, <username> for forks (including your own)” is much better, and there are a lot of people who do it that way.

Have this error. It ask me to choose repo, I did wrong choice. And then I have to use -R always. How to clear my choice of repo?

In case someone else runs into this like I did, If you open .git/config you’ll see the line gh-resolved = base. Move that line to the remote you want and it will now use it as the base.

  • i finally solved this by removing all remotes, including origin, re-adding origin, then adding upstream.
  • failed miserably prior to this hack, no matter what attempts i tried and no matter that the remotes were already correct.
  • gh version 1.10.3 (2021-05-21)
  • may have to repair local similar to git push --set-upstream origin master after the fix.

Saw this the other day, realized my gh version was ancient, upgraded and it worked… asked me which repo to use.

Today I got the error again. Do I need to tell it to re-prompt me somehow?

master> gh --version
gh version 1.4.0 (2020-12-15)
https://github.com/cli/cli/releases/latest
master>gh pr checkout 1173
GraphQL error: Could not resolve to a PullRequest with the number of 1173.

using the url option worked fine.

I can confirm that this is no longer an issue for me too, because it now ask which remote to use.

$ gh --version
gh version 1.2.0 (2020-10-27)

This issue should be closed.

I don’t think this issue is still happening. I have a fork of cli/cli and when I ran the command:

$ gh pr checkout 2230

It asked me which should be my base repository. 🤔

Version details:

~/code/go/src/cli(trunk) » gh --version                                                                                                                                                                              
gh version 1.1.0-77-g1ed4f049 (2020-10-27)
https://github.com/cli/cli/releases/latest

Correct, jbox-web/redmine_git_hosting is a fork (of a fork of a fork of a fork, believe or not !). But it has now outlived all ancestors (by far), and it should be considered as an independent project by now. But of course there is no way for cli/cli to know that.

What would be super useful, if this cannot be fixed easily, is to have a slightly more verbose message including the repository that was assumed. I tried --debug, --verbose flags to no avail. Something like:

  graphql error: 'Could not resolve to a PullRequest with the number of 759.'
+ with repository: kubitron/redmine_git_hosting
+ did you mean `gh pr checkout --repo jbox-web/redmine_git_hosting 759` ?