Repository navigation
Replies: 3 comments 7 replies
|
Hey @escarls 👋 apologies for the friction here. I want to say first off, that this is great feedback - so thank you 🙇 Second, an explanation for why we chose If I'm reading this right, it sounds what you're looking for is a token environment variable specifically for GitHub enterprise cloud tenants, that would override
There's probably some code in |
|
Based on The current behavior is:
So for a tenant like That also means I don't think there is a built-in env-only setup where:
For GitHub Enterprise Cloud, the practical env-only options seem to be:
So the short version is: your |
|
You can keep both tokens in environment variables and choose one per invocation, rather than changing the exported # WORK_GH_TOKEN and PERSONAL_GH_TOKEN are your own variable names,
# injected by your devcontainer or secret manager, not recognized by gh.
gh_work() {
GH_HOST=company.ghe.com GH_TOKEN="${WORK_GH_TOKEN:?WORK_GH_TOKEN is unset or empty}" \
command gh "$@"
}
gh_personal() {
GH_HOST=github.com GH_TOKEN="${PERSONAL_GH_TOKEN:?PERSONAL_GH_TOKEN is unset or empty}" \
command gh "$@"
}
gh_work api user --jq .login
gh_personal api user --jq .login
gh_work auth status --hostname company.ghe.comThis is Bash syntax. The assignments apply to that command and do not replace the parent shell's token. Both For repository commands, explicitly select the repository when switching contexts, for example For the extra github.com entry in Prepared with AI assistance and checked against the current CLI documentation. I have not tested authentication against your tenant. |
Uh oh!
There was an error while loading. Please reload this page.
At my previous employer, we used github as an org on github.com.
Back then, I used github cli with only the GH_TOKEN environment variable and no config file.
That worked like a charm for work and hobby projects, as they could in theory just use the same token.
My new employer however, have github enterprise hosted at company.ghe.com
And since it was Github Enterprise, I assumed it was just to follow the docs and have two tokens.
The GH_TOKEN for regular github and GH_ENTERPRISE_TOKEN for the company.ghe.com.
Well, that didn't work well.
So I discovered in the doc that I needed to set the GH_HOST environment variable when I was in a work repo, so gh would access the correct api. But still no go.
With the setup:
GH_TOKEN=
GH_ENTERPRISE_TOKEN=
GH_HOST=<company.ghe.com>
I only got error that the token was invalid.
So after spending some time testing back and forth, different things, like:
GH_COMPANY_GHE_COM_TOKEN=
and so on, nothing worked.
Then I just tested for fun:
How about if I just do:
GH_TOKEN=
Then everything worked (sort of).
gh auth statusshowed me this output:
Then I started looking into the github cli code a bit and then I understood why it was like this.
The unit tests for the IsEnterprise function expects "tenant.ghe.com" to return false, and I guess (didn't check) that this is the reason that the GH_ENTERPRISE_TOKEN env variable is not used.
So because of this, how can I create a setup, where I only have to set/unset GH_HOST to switch between work (ghe.com) and hobby projects (github.com)?
The reason for not wanting to use the "gh auth login" and create config, is that I'm mostly developing in devcontainers and then it's alot easier to just work with env variables for everything.
Also looking at the output from gh auth status, it seems there are more things going on there also.
I would have expected the output to just show the company.ghe.com part, as I have nothing here that hints to github.com, except for the GH_TOKEN variable, that was required for my company.ghe.com host.
All reactions