Repository navigation
Description
Summary
Commands like gh pr checkout, gh pr create, and gh repo fork fail with "none of the git remotes configured for this repository correspond to the GH_HOST environment variable" when the git remote hostname differs from the GitHub API hostname, even though this is a legitimate enterprise configuration.
Problem
In enterprise environments with git proxies or SSH bastions, git operations may route through a different hostname than API operations:
- Git operations:
git.company.com(proxy/bastion) - API operations:
github.company.com(GitHub Enterprise)
gh currently rejects this configuration and returns an error, preventing commands that perform git operations from working.
Reproduction
Setup:
# Repository with git remote through proxy
$ git remote -v
origin [email protected]:corp/repo.git
# Authenticated to GitHub Enterprise
$ gh auth login --hostname github.company.com
✓ Logged in as user
# Set GH_HOST to point to API
$ export GH_HOST=github.company.comError:
$ gh pr checkout 123
none of the git remotes configured for this repository correspond to the
GH_HOST environment variable. Try adding a matching remote or unsetting the variableCommands affected:
gh pr checkoutgh pr creategh repo forkgh repo syncgh issue develop
Commands that work fine:
gh pr view✓gh pr list✓gh issue view✓gh api✓
Root Cause
In pkg/cmd/factory/remote_resolver.go:82-92, gh returns an error when no git remotes match authenticated hosts, even though this validation is unnecessarily strict for commands performing git operations.
Analysis
For git operations, gh:
- ✅ Matches remotes by owner/repo (not hostname)
- ✅ Uses remote name like "origin" for git commands
- ❌ Never actually uses the remote hostname
For API operations, gh:
- ✅ Uses hostname from
GH_HOSTor auth config - ✅ Already validated separately
- ❌ Never uses git remote hostname
The git remote hostname and API hostname are separate concerns that shouldn't be coupled.
Real-World Use Cases
This affects enterprises using:
-
Git proxies - Route git traffic through internal proxies for security/auditing
- Example: Netflix uses
git.netflix.netfor git ops,github.netflix.netfor API
- Example: Netflix uses
-
SSH bastions - Git operations through jump hosts for security
- Example:
git.bastion.company.com→github.company.com
- Example:
-
Git mirrors - Internal mirrors for performance with different hostnames
- Example:
git.mirror.company.com→github.company.com
- Example:
-
Split DNS - Different internal/external hostnames
- Example:
git.internal.company.com→github.company.com
- Example:
-
CDN/load balancers - Git traffic load balanced separately
- Example:
git.cdn.company.com→github.company.com
- Example:
Expected Behavior
gh pr checkout 123 should:
- Match git remote by owner/repo (regardless of hostname)
- Use the matched remote for git operations
- Use
GH_HOSTfor API operations - Work successfully when both are available
The hostname mismatch should not be an error since these are separate concerns.
Current Workaround
Enterprises currently must maintain wrapper scripts that reimplement portions of gh CLI functionality, specifically pr checkout, to work around this limitation.
Additional Context
- This is a regression from expected git behavior where remotes are matched by repository identity, not hostname
- API authentication is already properly validated through
GH_HOSTand auth config - The hostname filtering is overly defensive and breaks legitimate enterprise setups
- I have a working fix for this that I can contribute via PR
Impact
Without this fix:
- ❌ Enterprise users cannot use
gh pr checkoutwith git proxies - ❌ Teams must maintain custom wrapper scripts
- ❌ Reduced adoption of gh CLI in enterprise environments
With this fix:
- ✅ Works with git proxies, bastions, and mirrors
- ✅ Maintains all security through proper API auth
- ✅ No impact on standard configurations
- ✅ Better separation of concerns
Environment:
ghversion: 2.83.1- OS: macOS, Linux
- GitHub type: GitHub Enterprise Server
Note: I have a tested implementation of a fix for this issue. See PR #12180.
Activity
Allow git operations when remote host differs from API host
Allow git operations when remote host differs from API host
williammartin commentedon Nov 24, 2025
Oooh, this looks like a duplicate of #10891. Will have to double check though!
Allow git operations when remote host differs from API host
Allow git operations when remote host differs from API host
github-actions commentedon Mar 2, 2026
Thank you for your issue! We have categorized it as an enhancement (feature or improvement) request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.
Unless you see the help wantedContributions welcome
label, we are not currently looking for external contributions for this feature.
If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.
BagToad commentedon Mar 2, 2026
I don't think this is a duplicate of #10891; they share the same error message but have different root causes. #10891 appears to be about SSH-format remotes (
git@) not resolving on the same host, while this issue is about intentionally different hostnames (git proxy/bastion vs API host).I closed #12180 because the proposed fix appeared to remove diagnostic error messages that help users troubleshoot other configuration issues. I think this needs more investigation and design work.
davidlin-stripe commentedon May 9, 2026
Hi team, has there been any updates on the investigation? I think it's a valid enterprise setup that is currently not nicely supported due to the way the resolver is setup - there should be configuration that supports some kind of overwrite.
Basically the pain has been coming from the git operations and the API operations hits different remotes, could we keep the entries in hosts.yml as the canonical host that handles the git operations but add a new configuration entry like
api_base_urlorapi_hostattached to the canonical host, and we can inject this at the http client level to perform the overwrite on the API operations - the rest of the logics remain unchanged and it makes the resolver happy.The caveat is the setup requires some explicit configuration, which often is already done or documented for folks in an enterprise setting, and the
gh auth loginrequires some proper care. We would need an extra flag to configure the api host at the auth time and reasonably assume the auth urls is based on api host instead of the git host, something likeI'd love to discuss this further - feedback or concern are welcomed.
[-]gh pr checkout fails when git remote host differs from GitHub API host[/-][+]`gh pr checkout` fails when git remote host differs from GitHub API host[/+]fix(pr): fall back to disambiguated GitHub remote
DerekStride commentedon May 28, 2026
I have a narrower variant of this issue that may avoid the concern raised in #12180.
Setup:
The current branch tracks origin, but origin is a mirror and is filtered out by remote resolution.
gh pr viewthen fails with:could not resolve remote "origin": no matching remote foundHowever, there is an unambiguous GitHub remote available: github.
It should be possible to scan the remote list to identify the correct org & repo, would this narrower approach be acceptable?
williammartin commentedon Jul 28, 2026
@davidlin-stripe I'm just back from parental leave and was picking up a similar thread from #13717 which looks almost identical and in fact, your PRs look similar at a glance. This has made its way to the top of my priority list. I haven't decided exactly whether these are precise duplicates yet, but in terms of having an
api_hostor similar field in config, I will be working over on that issue if you'd like to follow along.davidlin-stripe commentedon Jul 28, 2026
Thank you for following up William, looking at #13717 it's largely identical to the use case I've described, I will keep an eye on it and it will be great to have this in the upstream!