Visitar URL original
gh fails to resolve repository when git url.*.insteadOf rewrites remote URLs · Issue #12916 · cli/cli · GitHub
Skip to content

gh fails to resolve repository when git url.*.insteadOf rewrites remote URLs #12916

Open

Description

@simonferquel-clanker

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

  1. Configure a git insteadOf rule in system or global config:
# /etc/gitconfig
[url "http://my-proxy:9989/"]
    insteadOf = https://github.com/
  1. Clone a GitHub repo (works fine because git applies the rewrite transparently):
git clone https://github.com/owner/repo.git
  1. Run any gh command 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

  1. added a commit that references this issue on Mar 12, 2026
    2d5078f
  2. williammartin commented on Mar 12, 2026

    @williammartin
    Member

    @simonferquel presumably this is an agent acting on your behalf?

  3. simonferquel commented on Mar 13, 2026

    @simonferquel

    It is, but I assume responsibility on it.
    I explicitly told it to send the issue after it told me about its findings.

  4. williammartin commented on Mar 13, 2026

    @williammartin
    Member

    Cool, thanks. We'll get round to triaging this soon hopefully 👍

  5. BagToad commented on Mar 13, 2026

    @BagToad
    Member

    I think this is closely related to #12179.

    As a workaround, I think you can set GH_REPO to skip remote resolution entirely:

    # Tell gh which repo to use, bypassing git remote parsing
    export GH_REPO=owner/repo
    
    # Commands should now work
    gh pr list
    gh issue list

    Like #12179, this is an enhancement to how gh resolves remotes, so I'm marking it as such and adding it to our enhancement backlog.

    Related Links

  6. added
    enhancementa request to improve CLI
    and removed on Mar 13, 2026
  7. github-actions commented on Mar 13, 2026

    @github-actions
    Contributor

    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 wanted Contributions 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.

  8. added
    authrelated to tokens, authentication state, or oauth
    gh-prrelating to the gh pr command
    on Mar 13, 2026
  9. 2cs2vprhyf-creator commented on Aug 28, 2026

    @2cs2vprhyf-creator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    authrelated to tokens, authentication state, or oauthconfigenhancementa request to improve CLIgh-prrelating to the gh pr commandstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions