Repository navigation
Open
Labels
bugSomething isn't workinggh-prrelating to the gh pr commandmore-info-neededMore info needed from user/contributorneeds-triageneeds to be reviewed
Description
Describe the bug
When using GH_HOST, GH_REPO, and GH_ENTERPRISE_TOKEN in conjunction with gh pr create, it started failing about a week ago for us, and we can't reproduce as a human (even with a token) or determine any glaring differences between the CI/CD and local invocations of the same tool, nor even with any version bumps since the last working version (even if we downgrade to 2.70.0, it still fails now 2.70.0 still works actually).
could not resolve remote "origin": none of the git remotes configured for this repository correspond to the GH_HOST environment variable. Try adding a matching remote or unsetting the variable
Some of the settings/troubleshooting attempts
GH_HOST=our.enterprise.host
GH_REPO=out.enterprise.host/ourorg/ourrepo
GH_ENTERPRISE_TOKEN=<set to something>
GH_DEBUG=true
00:00:45 + git remote -v
00:00:45 origin [email protected]:ourorg/ourrepo (fetch)
00:00:45 origin [email protected]:ourorg/ourrepo (push)
00:00:45 + git version
00:00:45 git version 2.43.5
00:00:45 + gh version
00:00:45 gh version 2.71.2 (2025-04-24)
00:00:45 + git config --get-regexp '^branch\.autoupdate/20250428-183455\.(remote|merge|pushremote|gh-merge-base)$'
00:00:45 branch.autoupdate/20250428-183455.remote origin
00:00:45 branch.autoupdate/20250428-183455.merge refs/heads/autoupdate/20250428-183455
00:00:45 + git rev-parse --symbolic-full-name 'autoupdate/20250428-183455@{push}'
00:00:45 refs/remotes/origin/autoupdate/20250428-183455
and invocation
00:00:45 + gh pr create --label autoupdate-server_admap --title '[autoupdate][20250428-183455] Update files from source folder' --body 'This PR is a result of script, which auto update files from the source directory.'
00:00:45 [git remote -v]
00:00:45 [git config --get-regexp ^remote\..*\.gh-resolved$]
00:00:45 * Request at 2025-04-28 18:34:59.675488605 +0000 UTC m=+0.085715954
00:00:45 * Request to https://our.enterprise.host/api/graphql
00:00:46 * Request took 245.740739ms
00:00:46 [git status --porcelain]
00:00:46 [git symbolic-ref --quiet HEAD]
00:00:46 [git config --get-regexp ^branch\.autoupdate/20250428-183455\.(remote|merge|pushremote|gh-merge-base)$]
00:00:46 [git rev-parse --symbolic-full-name autoupdate/20250428-183455@{push}]
00:00:46 could not resolve remote "origin": none of the git remotes configured for this repository correspond to the GH_HOST environment variable. Try adding a matching remote or unsetting the variable
Affected version
Please run gh version and paste the output below.
gh version 2.71.2 (2025-04-24)
Steps to reproduce the behavior
- Have an enterprise server
- Set the GH_HOST, GH_REPO, GH_ENTERPRISE_TOKEN appropriately
- Have an origin with ssh-formatted location (not quite URL but git@ style)
Expected vs actual behavior
A PR should be created (and was up until a week ago); the error regarding inability to find the origin is output and a failure rc is returned.
Logs
See invocation above
Reacted by tommyjr11
Metadata
Metadata
Assignees
Labels
bugSomething isn't workinggh-prrelating to the gh pr commandmore-info-neededMore info needed from user/contributorneeds-triageneeds to be reviewed
Activity
williammartin commentedon Apr 28, 2025
Hmmm sorry for the inconvenience. If possible can you provide the debug logs with 2.70.0 as well? Would just like to double check something.
scr-oath commentedon Apr 28, 2025
Actually… I think we didn't actually try with 2.70.0 - there were two cases where the downgrade was done and the place we were eyeballing didn't have the downgrade… we're trying it again now… if that fixes things, I'll let you know!
scr-oath commentedon Apr 28, 2025
v2.70.0 actually DOES work afterall, still.
williammartin commentedon Apr 29, 2025
Makes sense that the problem would be introduced in 2.71.0 with all the changes we made around respecting git config on
pr create. Thanks for the extra information!williammartin commentedon Apr 29, 2025
So, the only explanation I have for this right now is that we were previously suppressing an error:
cli/pkg/cmd/pr/create/create.go
Line 966 in e138782
And the same codepath that was called here is now called later with the error unsuppressed:
cli/pkg/cmd/pr/shared/find_refs_resolution.go
Line 260 in e138782
However, I cannot reproduce your error with a valid setup:
The only way I can reproduce it is if I misconfigure
GH_HOST:Then
v2.71.0fails wherev2.70.0passes:Or, if I misconfigure the
git remote:This is strange behaviour but works because the value of
GH_REPOis used to determine the host to target for API requests, and because the branch is already pushed, there's no need to use the git remote.It's highly likely that I'm missing something here, but can you please double check
GH_REPO,GH_HOSTandgit remote -vconfiguration. If you don't think you can share these publicly but are willing to share with me you can email me at my handle@github.com.[-]could not resolve remote "origin": none of the git remotes configured for this repository correspond to the GH_HOST environment variable.[/-][+]could not resolve remote "origin": none of the git remotes configured for this repository correspond to the `GH_HOST` environment variable.[/+]scr-oath commentedon Apr 30, 2025
hi - sent an email with fuller logs… if you have any public slack/irc/other connectivity to chat please LMK if you have patience to troubleshoot closer to "live"
williammartin commentedon May 5, 2025
Investigation Summary
The error:
Comes from our code that "resolves remotes" which is a process of:
hosts.ymlorGH_HOSTenv var, orgithub.com)In the case of a user providing the
GH_HOSTenv var, we expect to only retain the git remotes for those with a repo host that matches exactly the value of `GH_HOST.SSH Translation
SSH Translation is the process of taking a git remote that is an SSH URL (e.g.
[email protected]:cli/cli) and askingsshwhether the host (github.com) is being mapped to some other hostname. This mapping usually lives in~/.ssh/configand looks like:It's important that
ghdoes this translation in order to send API requests to the real host, for example, when creating a pull request.Problem
If a user does not have a host in the
hosts.yml, the only way they can indicate the presence of a known host toghis via theGH_HOSTenvironment variable. ThisGH_HOSTenvironment variable is used by commands that don't have a base repo to provide the host (e.g.gh repo list) to determine the API endpoint. Without this environment variable set, remotes for an expected host will be filtered out as per the bullet list above and also as per the bulleted list above, it is expected that the value ofGH_HOSTexactly matches the repo's hostname, after SSH translation.So given I want to create a PR in my enterprise server that doesn't exist in
hosts.yml, a user must passGH_HOSTHowever if my enterprise setup also has a hostname mapping to force ssh requests to go through a proxy:
Then after SSH translation
myghes.comwill not matchssh-proxy.myghes.comand no remotes will be retained.Evidence
In trunk...wm/debug-gh-host-ssh-translate, you will find a commit with acceptance test that demonstrates this behaviour (requires some manual patching of
go-ghto avoid writing to a real SSH config), and a commit with a series of debug logs sprinkled throughout.Here is the output of the debug logs for this test:
We can see the translation of our
FetchURLAnd that the later comparison uses the translated URL:
Why didn't this fail before?
Alluded to in #10891 (comment), before
v2.71.0we were suppressing this error in the only place that remotes were resolved duringpr createcli/pkg/cmd/pr/create/create.go
Lines 960 to 971 in e138782
However, with the changes in
v2.71.0, we started calling this function in another location and are not suppressing the error:cli/pkg/cmd/pr/shared/find_refs_resolution.go
Lines 255 to 262 in e138782
This may indicate another bug that I need to look into with regards the comment:
But that is outside the scope of this investigation.
What do we do next?
Todo, since it's a vacation day here but I wanted to write this up for the team to look at.
andyfeller commentedon May 5, 2025
If I understand everything above, it seems like the problem is that resolving remotes does not consider the SSH aliasing case below:
cli/pkg/cmd/factory/remote_resolver.go
Lines 72 to 80 in d6d8275
Should this line also include the translated version of the hosts when trying to resolve the remotes? If so, does the ordering matter? Should a translated host have higher precedence?
scr-oath commentedon May 5, 2025
Well the latest debugging with @williammartin has shown that
$HOME/.ssh/configI don't like needing to know how my ssh is configured to make the tool work, but would be ok with some flag or env var to disable the ssh inspection if that could be possible in the tool.
scr-oath commentedon May 5, 2025
I suppose, we could learn about, and provide a yaml file if that would fix the behavior- I think we want/need the REST stuff to go to the named host, even if the ssh stuff (push/pull) goes through the x509 proxy.
scr-oath commentedon May 5, 2025
I don't see mention of
hosts.ymlin the https://cli.github.com/manual/gh_pr_create (don't see any search there either, so clicked around to a few places I thought it might be but came up empty for in-page search for hosts.yml).williammartin commentedon May 6, 2025
host.ymlis an implementation detail. When a user runsgh auth loginthe targeted host is persisted along with any other configuration (e.g. chosen git protocol, token if using--insecure-storage).williammartin commentedon May 14, 2025
@scr-oath, one other workaround occurred to me today. If I recall correctly, your workflow is creating a PR from a branch that already exists remotely, before you run
gh pr create. If you provided the--headflag with the name of that branch (orowner:branchif it is in a fork) thenghwill choose a different code path than the one that results in the error surfacing.I appreciate this still isn't exactly what you want, but I think it's probably an improvement over setting
GH_HOSTto the value of the resolved SSH hostname?scr-oath commentedon May 14, 2025
Interesting, yes, we do git push before invoking gh pr create… I can try adding that flag to see if it helps… stay tuned; will update this comment.