Skip to content

gh uses git remote string and ignores SSH host aliases #6455

Closed

Description

@medecau

Describe the bug

Unable to use gh in repo where remote uses different host alias.

I use different alias for github.com as remotes so I can have repos that use personal or work ssh keys.

Steps to reproduce the behavior

  1. Have an SSH key file like ~/.ssh/work.pub that is listed in your GH SSH keys
  2. Add the following to your ~/.ssh/config
Host github-enterprise
	IdentityFile "~/.ssh/work.pub"
Host github-*
	Hostname github.com
	IdentitiesOnly yes
  1. Pick a for your account and change the origin remote to git@github-enterprise:<org>/<repo>.git
  2. Attempt to use gh on the repo with the modified remote

Expected vs actual behavior

When running a gh pr checkout <PR number> it fails with the following message:

could not determine base repo: 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`

I've tried to re-auth, but the issue remains. I've also tried to add github-enterprise as a GH host, but that didn't work either and I feel silly for having tried it.

I expected the same behaviour as with a remote pointing to github.com.

Activity

  1. added
    bug
    on Oct 18, 2022
  2. added
    needs-triage
    on Oct 18, 2022
  3. samcoe commented on Oct 20, 2022

    @samcoe
    Contributor

    @medecau Thanks for writing in. Right now our parsing of SSH config files is basic and does not handle wildcard characters such as *. To work around this limitation I would suggest that you add the Hostname field to each individual Host entry. Please let me know if that works for you.

  4. added
    more-info-needed
    and removed
    needs-triage
    on Oct 20, 2022
  5. medecau commented on Oct 27, 2022

    @medecau
    Author

    Yes, adding Hostname github.com to each individual Host entry resolves this issue.

    Thank you @samcoe.

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

    bugmore-info-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions