Repository navigation
Conversation
A fine-grained token is scoped to a single organization, but the CLI resolved exactly one token per host, so a single gh install could not drive several orgs (or run concurrent processes against different orgs). This adds Phase 1 of cli#12888: - `gh auth login --with-token --org <label>` stores a token under an org label instead of the GitHub login, so multiple tokens owned by the same login can coexist on one host without overwriting each other. The real login and org are recorded as account metadata. - `GH_AUTH_ACCOUNT` selects which stored account to use for a single invocation without changing the active account, enabling concurrent gh processes to target different orgs in parallel. It is gated by a config-only membership check (no keyring probe on unknown values) and is ignored when an explicit env token is set. - `gh auth status` surfaces the account label and organizations for org-scoped accounts; classic single-account output and JSON are unchanged. `gh auth switch` selects these accounts by their org label. - Document GH_AUTH_ACCOUNT in the environment help topic. Config storage is backward compatible: sibling accounts and the new `user`/`orgs` keys live under `hosts.<host>.users.<account>`, which go-gh ignores, so no hosts.yaml migration is required. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Show the before/after hosts.yml for cli#12888 so the additive schema is concrete: org-scoped accounts are keyed by the org label and add optional `user` (real login) and `orgs` fields, while classic accounts and their files are untouched. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Add --dest-auth/--source-auth so gh repo sync can read upstream and write the fork with separate stored account tokens, falling back to a temporary git fetch/push when merge-upstream cannot span two orgs. Include a reproducible cross-build script for local darwin/linux testing. Co-authored-by: Cursor <[email protected]>
rastaman
force-pushed
the
feat/multi-org-tokens-12888
branch
2 times, most recently
from
July 23, 2026 16:11
328d165 to
6bf4c97
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this exists
Upstream context: cli/cli#12888
Summary
This fork implements:
ghinstall (per-org account keys).gh repo syncusing two stored tokens when classic PATs are forbidden.Problem
ghresolves one active token per host, which is awkward for multi-org workflows.gh repo syncusesPOST /repos/.../merge-upstream, which authenticates with one credential that must see both fork and upstream. Cross-org sync with FG PATs fails withHTTP 403: Resource not accessible by personal access token, even when each org has a valid FG token with Contents write.Real-world case that triggered this:
ludopro/clients-syncmyorg/clients-syncludoandmyorgWhat was implemented
1. Multiple fine-grained tokens per host
Commits:
a27e72910— feat(auth): support multiple fine-grained tokens per host (Support multiple fine-grained tokens forgh auth switchcli/cli#12888)346f8e89e— docs(auth): sample hosts.yml for the multi-org schemaBehavior:
gh auth login --with-token --org ACMEstores the token under account keyACME.users.<accountKey>:user(real login) andorgs.GH_AUTH_ACCOUNT=<accountKey>.Docs:
docs/multi-org-tokens.md2. Dual-token cross-org
gh repo syncCommit:
6bf4c9754— feat(repo-sync): dual-token cross-org sync for fine-grained PATsNew flags:
When either flag is set:
--sourceis required (parent discovery needs one token that can see both orgs; FG tokens usually cannot).merge-upstreamis skipped (single-credential API cannot span two orgs).Example:
3. Reproducible cross-build script
script/build-cross.shbuildsdarwin/arm64,linux/arm64, andlinux/amd64withCGO_ENABLED=0,-trimpath, andSOURCE_DATE_EPOCHfrom git HEAD. Outputs underdist/cross/<version>/plus checksums. Darwin arm64 was smoke-tested successfully.Explicitly not done (yet)
-Rmerge-upstreamitself accept two tokens (not possible: one Authorization header per request)cli/cliStatus
GH_AUTH_ACCOUNT/ account metadatarepo sync(refs + git fallback)