Repository navigation
Description
Description
gh commands that need to resolve a repository from git remotes (e.g. gh pr list, gh issue list, gh repo set-default) fail when url.<base>.insteadOf rules are configured in git config (typically at the system level in /etc/gitconfig).
Steps to reproduce
- Configure a git
insteadOfrule in system or global config:
# /etc/gitconfig
[url "http://my-proxy:9989/"]
insteadOf = https://github.com/- Clone a GitHub repo (works fine because git applies the rewrite transparently):
git clone https://github.com/owner/repo.git
- Run any
ghcommand that needs to resolve the repo from remotes:
cd repo
gh pr list
Expected behavior
gh pr list should succeed, resolving the repo from the remotes.
Actual behavior
none of the git remotes configured for this repository point to a known GitHub host.
To tell gh about a new GitHub host, please use `gh auth login`
Root cause
In git/client.go, the Remotes() function calls git remote -v to discover remote URLs. However, git remote -v applies url.<base>.insteadOf rewrites before displaying URLs. So when the system config rewrites https://github.com/ to http://my-proxy:9989/, gh sees my-proxy:9989 hostnames instead of github.com.
Later, in pkg/cmd/factory/remote_resolver.go, remotes are filtered by FilterByHosts() against known GitHub hosts. Since my-proxy:9989 is not a known host, all remotes are filtered out, and gh errors.
Meanwhile, git config --get-regexp ^remote\..*\.url$ returns the raw, un-rewritten URLs as stored in .git/config. These retain the original github.com hostname.
Context
This is a common setup in corporate/CI environments where a proxy or credential helper intercepts GitHub traffic via insteadOf rules. The gh SSH translator (go-gh/pkg/ssh) already handles SSH hostname aliasing for a similar reason, but there is no equivalent for HTTP insteadOf rewrites.
Proposed fix
After parsing remotes from git remote -v, additionally read raw URLs via git config --get-regexp ^remote\..*\.(url|pushurl)$ and overwrite the fetch/push URLs on each remote with the un-rewritten values. This is a single extra git config read with negligible cost, and it does not affect git transport commands (which continue to use insteadOf-rewritten URLs as normal).
Activity
Fix remote resolution when url.*.insteadOf rewrites GitHub URLs
williammartin commentedon Mar 12, 2026
@simonferquel presumably this is an agent acting on your behalf?
simonferquel commentedon Mar 13, 2026
It is, but I assume responsibility on it.
I explicitly told it to send the issue after it told me about its findings.
williammartin commentedon Mar 13, 2026
Cool, thanks. We'll get round to triaging this soon hopefully 👍
BagToad commentedon Mar 13, 2026
I think this is closely related to #12179.
As a workaround, I think you can set
GH_REPOto skip remote resolution entirely:Like #12179, this is an enhancement to how
ghresolves remotes, so I'm marking it as such and adding it to our enhancement backlog.Related Links
gh pr checkoutfails when git remote host differs from GitHub API host #12179, same root cause (FilterByHostsrejecting remotes with non-matching hostnames), covers the broader enterprise proxy/bastion scenariogo-ghSSH translatorgithub-actions commentedon Mar 13, 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.
2cs2vprhyf-creator commentedon Aug 28, 2026