Skip to content

Cannot override detected Github repo #13027

Open

Description

@toothbrush

Describe the bug

For boring work-related reasons, my git's remote."origin".url goes through a proxy, so the shape of the remote URL is not simply https://github.com/owner/repo.

This breaks things like gh pr view, because gh is unable to deduce the Github URL of my repo.

Affected version

$ gh version
gh version 2.88.1 (2026-03-12)
https://github.com/cli/cli/releases/tag/v2.88.1

Steps to reproduce the behavior

First, assume that my .git/config contains this: (i could reproduce my issue by simply git init a repo on my local machine and adding that config)

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://weird-proxy.com/github/owner/repo
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
    pushRemote = origin
[branch "some-feature-branch"]
    pushRemote = origin

Assume also that this really corresponds to a repo https://github.com/owner/repo hosted on Github. I'd like gh commands to work. For example:

$ gh browse # fails
unable to determine base repository: 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`
$ GH_REPO=owner/repo gh browse # works!
$ GH_REPO=owner/repo gh pr list --state all # works!

Now, i jump over to a feature branch some-feature-branch. I want to open a PR:

$ GH_REPO=owner/repo gh pr create
could not resolve remote "origin": 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`
$ gh repo set-default toothbrush/SeeKee # just a random example repo that exists in reality
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`

At this point i'd expect gh to respect GH_REPO and go from there, but it seems it doesn't. Somewhere #2300 i saw a reference to gh-resolved, but that also doesn't help in my case.

git config --local "remote.origin.gh-resolved" https://github.com/owner/repo

Expected vs actual behavior

I'd expect a flag or env var that I could set, to force gh to use a given Github repo as the target for my operations.

I could also imagine offering some kind of repo-local config flag (a bit like gh-resolved) to tell gh specifically what Github repo a remote corresponds to. E.g., in .git/config:

[remote "origin"]
    url = https://weird-proxy.com/github/owner/repo
    gh-repo-url = https://github.com/toothbrush/foo
    fetch = +refs/heads/*:refs/remotes/origin/*

This way i could configure a weird proxy for my own push/pull actions, but still benefit from gh operations.

Activity

  1. williammartin commented on Mar 26, 2026

    @williammartin
    Member

    Thanks for the detailed writeup. Just trying to understand your set up here, do you do gh auth login and if so where do you target? Or do you set GH_HOST and GH_TOKEN? What URL does your API endpoint live at (https://weird-proxy.com/github/api/v3?`), or is this proxy only a git proxy and the API lives elsewhere?

  2. toothbrush commented on Mar 27, 2026

    @toothbrush
    Author

    Yep good questions. I still expect API things to run directly against regular Github, so indeed i would just:

    cd ~
    gh auth login # regular login flow on github.com

    I do not have GH_HOST or GH_TOKEN set – i tried using GH_HOST in my weirdly-configured project to force gh to use normal Github.com, but that failed because then it filters out origins that don't look like normal Github.com and fails.

    The proxy is indeed only for Git push & pull. The commits end up on Github.com and we continue to use Github.com for PRs and so on, but i'd like to be able to use the gh tool, too.

  3. toothbrush commented on Mar 27, 2026

    @toothbrush
    Author

    As a discussion starter, i made a patch that solves my issue. I don't know if it's a desirable approach.

    I was able to git config remote.origin.gh-repo-url [email protected]:owner/repo.git and have gh perform operations against the Github repo i intend.

    From 793d68713ae1d4ee5b50f0326047741b1366e44d Mon Sep 17 00:00:00 2001
    From: paul <[email protected]>
    Date: Wed, 25 Mar 2026 16:05:52 +0930
    Subject: [PATCH] Support remote.<name>.gh-repo-url config to override repo URL
    
    When a git remote uses a non-GitHub URL scheme (e.g., a corporate
    proxy), gh cannot deduce the GitHub repository from the remote URL.
    This adds support for a `gh-repo-url` git config field per remote
    that, when set, overrides the FetchURL and PushURL used by gh to
    determine the target GitHub repository.
    
    Usage: git config remote.origin.gh-repo-url [email protected]:owner/repo.git
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
    ---
     git/client.go      | 45 +++++++++++++++++++++++++++++++++++++++++++++
     git/client_test.go | 31 +++++++++++++++++++++++++++++++
     2 files changed, 76 insertions(+)
    
    diff --git a/git/client.go b/git/client.go
    index 5f547c99c..c5765d917 100644
    --- a/git/client.go
    +++ b/git/client.go
    @@ -186,8 +186,22 @@ func (c *Client) Remotes(ctx context.Context) (RemoteSet, error) {
     		}
     	}
     
    +	repoURLArgs := []string{"config", "--get-regexp", `^remote\..*\.gh-repo-url$`}
    +	repoURLCmd, err := c.Command(ctx, repoURLArgs...)
    +	if err != nil {
    +		return nil, err
    +	}
    +	repoURLOut, repoURLErr := repoURLCmd.Output()
    +	if repoURLErr != nil {
    +		var gitErr *GitError
    +		if ok := errors.As(repoURLErr, &gitErr); ok && gitErr.ExitCode != 1 {
    +			return nil, gitErr
    +		}
    +	}
    +
     	remotes := parseRemotes(outputLines(remoteOut))
     	populateResolvedRemotes(remotes, outputLines(configOut))
    +	populateRepoURLOverrides(remotes, outputLines(repoURLOut))
     	sort.Sort(remotes)
     	return remotes, nil
     }
    @@ -965,6 +979,37 @@ func populateResolvedRemotes(remotes RemoteSet, resolved []string) {
     	}
     }
     
    +// populateRepoURLOverrides applies gh-repo-url config overrides to remotes.
    +// When remote.<name>.gh-repo-url is set, its value is parsed as a git URL and
    +// used to override the FetchURL and PushURL of the matching remote. This allows
    +// users to point gh at a different GitHub repository than what the remote URL
    +// normally resolves to.
    +func populateRepoURLOverrides(remotes RemoteSet, overrides []string) {
    +	for _, l := range overrides {
    +		parts := strings.SplitN(l, " ", 2)
    +		if len(parts) < 2 {
    +			continue
    +		}
    +		rp := strings.SplitN(parts[0], ".", 3)
    +		if len(rp) < 2 {
    +			continue
    +		}
    +		name := rp[1]
    +		urlStr := strings.TrimSpace(parts[1])
    +		u, err := ParseURL(urlStr)
    +		if err != nil {
    +			continue
    +		}
    +		for _, r := range remotes {
    +			if r.Name == name {
    +				r.FetchURL = u
    +				r.PushURL = u
    +				break
    +			}
    +		}
    +	}
    +}
    +
     var globReplacer = strings.NewReplacer(
     	"*", `\*`,
     	"?", `\?`,
    diff --git a/git/client_test.go b/git/client_test.go
    index f59b26077..74fd8331b 100644
    --- a/git/client_test.go
    +++ b/git/client_test.go
    @@ -148,6 +148,37 @@ func TestClientRemotes(t *testing.T) {
     	assert.Equal(t, "other", rs[3].Resolved)
     }
     
    +func TestClientRemotes_gh_repo_url(t *testing.T) {
    +	tempDir := t.TempDir()
    +	initRepo(t, tempDir)
    +	gitDir := filepath.Join(tempDir, ".git")
    +	remoteFile := filepath.Join(gitDir, "config")
    +	remotes := `
    +[remote "origin"]
    +	url = corpoproxy://somehost.com/git/monalisa/origin
    +	gh-repo-url = [email protected]:monalisa/origin.git
    +[remote "upstream"]
    +	url = https://github.com/monalisa/upstream.git
    +`
    +	f, err := os.OpenFile(remoteFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0755)
    +	assert.NoError(t, err)
    +	_, err = f.Write([]byte(remotes))
    +	assert.NoError(t, err)
    +	err = f.Close()
    +	assert.NoError(t, err)
    +	client := Client{
    +		RepoDir: tempDir,
    +	}
    +	rs, err := client.Remotes(context.Background())
    +	assert.NoError(t, err)
    +	assert.Equal(t, 2, len(rs))
    +	assert.Equal(t, "upstream", rs[0].Name)
    +	assert.Equal(t, "https://github.com/monalisa/upstream.git", rs[0].FetchURL.String())
    +	assert.Equal(t, "origin", rs[1].Name)
    +	assert.Equal(t, "ssh://[email protected]/monalisa/origin.git", rs[1].FetchURL.String())
    +	assert.Equal(t, "ssh://[email protected]/monalisa/origin.git", rs[1].PushURL.String())
    +}
    +
     func TestClientRemotes_no_resolved_remote(t *testing.T) {
     	tempDir := t.TempDir()
     	initRepo(t, tempDir)
    -- 
    2.51.2
  4. added
    enhancement
    gh-repo
    on Mar 30, 2026
  5. removed
    needs-triage
    on Mar 30, 2026
  6. github-actions commented on Mar 30, 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.

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

    enhancementgh-repostale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions