Authenticate GitHub with gh tokens per repo, so two accounts can share one box - #15
Merged
Merged
Conversation
…e one box An ssh key can be registered on exactly one GitHub account, so a box with a personal and a work account could never authenticate as both -- the second registration is refused as a key already in use. Tokens have no such limit, and gh already stores one per account. The obvious move, `gh auth setup-git`, does not work here: its helper answers only for whichever account is active. With two accounts that is wrong half the time, and wrong in the worst way, because a read as the other account returns 404 rather than 403 -- indistinguishable from the repository not existing. So git resolves the account the way gh/gh already does: `gh.account` on the repo, or a username carried in the remote URL, then `gh auth token --user`. Read-only, never `gh auth switch`, which mutates shared state that concurrent sessions flip under each other. Identity is now one setting per repo, covering push, fetch, and every gh subcommand alike. The empty helper ahead of it resets the chain. Helpers accumulate across system, global and local config and are tried in order, so without it a system helper -- osxkeychain, or a leftover setup-git line -- answers first with the wrong account. Claude-Session: https://claude.ai/code/session_01AVTNMRmHsTJMauEwo2ryLv
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.
An ssh key can be registered on exactly one GitHub account, so a box with a personal and a work account could never authenticate as both — the second registration is refused as a key already in use. Tokens have no such limit, and gh already stores one per account.
gh auth setup-gitdoes not solve it: its helper answers only for whichever account is active. With two accounts that is wrong half the time, and wrong in the worst way, because a read as the other account returns 404 rather than 403 — indistinguishable from the repository not existing.So git now resolves the account the way
gh/ghalready does:gh.accounton the repo, or a username carried in the remote URL, thengh auth token --user. Read-only, nevergh auth switch, which mutates shared state that concurrent sessions flip under each other. Identity becomes one setting per repo, covering fetch, push and every gh subcommand alike.The empty helper ahead of it resets the chain — helpers accumulate across system, global and local config and are tried in order, so without it a system helper (osxkeychain, or a leftover
setup-gitline) answers first with the wrong account.Note that
~/.gitconfigis copied rather than symlinked (install.sh:98) and left alone when it already exists, so this reaches freshly provisioned accounts automatically and existing ones not at all.https://claude.ai/code/session_01AVTNMRmHsTJMauEwo2ryLv