cli/cli

Problem seeing private repos when logged into both github.com and a github enterprise instance

lasse-aagren opened this issue · 2 comments

Describe the bug

$ gh --version
gh version 2.48.0 (2024-04-17)
https://github.com/cli/cli/releases/tag/v2.48.0

When gh is logged into both github.com and github enterprise at github.mydomain, it can't list private repos with gh repo list <myenterpriseorg> - It only lists the public repos.

Steps to reproduce the behavior

  1. use gh auth login to log into your github enterprise
  2. use gh auth login to log into github.com
  3. run gh auth status to show successful connected to both:
$ gh auth status
github.mydomain
  ✓ Logged in to github.mydomain account someuser (keyring)
  - Active account: true
  - Git operations protocol: ssh
  - Token: gho_************************************
  - Token scopes: 'admin:public_key', 'gist', 'read:org', 'repo'

github.com
  ✓ Logged in to github.com account someuser (keyring)
  - Active account: true
  - Git operations protocol: ssh
  - Token: gho_************************************
  - Token scopes: 'admin:public_key', 'gist', 'read:org', 'repo
  1. run gh repo list <myenterpriseorg>
  2. see that it only lists public repositories
$ gh repo list <myenterpriseorg>

Showing 30 of 36 repositories in @myenterpriseorg

Expected vs actual behavior

If you log out of github.com using gh auth logout, and run gh repo list <myenterpriseorg> again, you'll see that it lists all the repos:

[:~] $ gh auth logout
? What account do you want to log out of? someuser (github.com)
✓ Logged out of github.com account someuser
[:~] $ gh repo list myenterpriseorg

Showing 30 of 3457 repositories in @myenterpriseorg

Hey! Thanks for the detailed issue, it makes it very easy to see what's going on.

gh only targets one host at a time for any command. By default it targets github.com if you are authenticated with more than one host but if you have just one authenticated host it will target that (hence why you see your enterprise repos after you logout of github.com). You can use the GH_HOST env var to target a specific host (you can find out more about env vars in gh environment.

That makes sense. Thanks for explaining.

Will close this ticket