-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Allow git operations when remote host differs from API host #12180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
|
Thank you for your pull request! 🎉 This PR appears to fix the following issues that are not labeled with
help wanted
As outlined in our Contributing Guidelines, we expect that PRs are only created for issues that have been labeled While we appreciate your initiative, please note that:
What happens next:
Thank you for your understanding and contribution to the project! 🙏 This comment was automatically generated by cliAutomation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #12179 by allowing git operations to work when the git remote hostname differs from the GitHub API hostname, which is common in enterprise environments using git proxies or SSH bastions.
Key Changes:
- Modified remote resolver to fall back to all remotes instead of failing when no remotes match authenticated hosts
- Removed error paths that prevented legitimate enterprise configurations from working
- Deleted unused
fmtimport after removing error formatting code
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Fall back to all remotes for commands that only need owner/repo matching. | ||
| // Commands performing API operations will still fail with clear errors when | ||
| // the API host is wrong. This allows git operations through proxies/bastions | ||
| // where the git remote host differs from the GitHub API host. | ||
| rr.cachedRemotes = resolvedRemotes |
Copilot
AI
Nov 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Falling back to all remotes without validation could allow commands to operate on unintended repositories. Consider adding a warning log or requiring explicit opt-in via configuration when operating in this fallback mode to make the behavior visible to users and prevent silent failures when configuration is genuinely incorrect.
Currently, gh rejects git remotes when their hostname doesn't match the authenticated GitHub host, even though this is a legitimate enterprise configuration. This prevents commands like `gh pr checkout` from working in environments with git proxies or SSH bastions. The validation is unnecessarily strict because: - Git operations only need owner/repo matching, not hostname matching - Git commands use the remote name (e.g., "origin"), not the URL - API operations already validate the host separately via GH_HOST This change allows all remotes to be considered when no remotes match authenticated hosts. Commands performing API operations will still fail appropriately with clear errors when the API host is wrong. Fixes cli#12179 Real-world scenario this fixes: - Git remote: git@git.company.com:corp/repo.git - API endpoint: github.company.com - Previously: "none of the git remotes configured" error - Now: Works correctly for git operations Changes: - Remove strict hostname validation in remote resolver - Fall back to all remotes for git operations - Remove unused fmt import
78008cc to
4d7b893
Compare
Summary
Fixes #12179 - Allows
gh pr checkoutand related commands to work when git remote hostname differs from GitHub API hostname.Problem
Commands like
gh pr checkout,gh pr create, andgh repo forkfail in enterprise environments where:git.company.com(proxy/bastion)github.company.com(GitHub Enterprise)Error encountered:
This affects legitimate enterprise configurations using git proxies, SSH bastions, or git mirrors.
Root Cause
The remote resolver in
pkg/cmd/factory/remote_resolver.goreturns an error when no git remotes match authenticated hosts, even though:origin), not the URLGH_HOSTThe git remote hostname and API hostname are separate concerns.
Solution
Changed the remote resolver to fall back to all remotes when no remotes match authenticated hosts, rather than failing with an error.
Before:
After:
Changes Made
pkg/cmd/factory/remote_resolver.go:fmtimportTesting
Test scenario:
Verified:
gh pr checkoutworks with mismatched hostnamesgh pr view,gh pr liststill work (API operations)Real-world testing:
Impact
Benefits:
Who this helps:
Security Considerations
GH_HOSTand auth configAlternative Considered
Created a separate
GitRemotes()factory method for git-only operations, but the fallback approach is simpler and achieves the same goal with less code.