Switching GitHub accounts without touching ~/.gitconfig
GitOS is a macOS git client that picks the right account for each repo. The whole design rests on one decision: account settings travel with each git command, not in global config.
If you have a work and a personal GitHub account, the failure is always small and always annoying: a push rejected because the wrong token answered, or a commit that goes out under the wrong email. The usual fixes are includeIf blocks, SSH host aliases or a switcher that rewrites your global config. I wanted the account to be a property of the folder a repo lives in, with nothing to remember.
One rule: never write to global config
Rewriting ~/.gitconfig means the current account is shared state, so a terminal in one repo can be changed by a click in another window. GitOS shells out to the real git CLI, and every command it runs gets its identity and credentials as -c flags and environment variables. They exist for that one process and then they're gone.
// From GitContext. The empty value clears every other helper,
// for github.com only, so osxkeychain can't answer with another
// account's token. Other hosts keep their normal helpers.
args += ["-c", "credential.https://github.com.helper=",
"-c", "credential.https://github.com.helper=\(Self.credentialHelper)",
"-c", "url.https://github.com/.insteadOf=git@github.com:"]The helper is a one-line shell function that prints the token from the environment. The insteadOf line means SSH remotes also go through the account's token, so nobody needs host aliases in ~/.ssh/config. user.name, user.email and signing settings are passed the same way. Tokens themselves live in the macOS Keychain.
Choosing the account
Resolution is three steps: a per-repo override wins, then the longest matching folder rule, then the default account. Longest match matters, because ~/Work/client can then differ from ~/Work. The toolbar's account button shows which account is active and why, because an automatic choice you can't see is hard to trust.
What the tests were for
A git client can quietly lose someone's work, so parser tests alone weren't enough. The suite also drives real git in temporary repos: rebases, merge conflicts and line-level staging. Rendering had its own surprises. A banner's description used a fixed vertical size, wrapped word by word at the narrowest layout probe, asked for about 2,000 points of height and pushed the whole window content off screen. The fix was a two-line limit.
What's still rough
- Sign-in uses GitHub's device flow, which needs a one-time OAuth App client ID pasted into Settings. That's fine for me and a real hurdle for anyone else.
- It's macOS only, and account switching is built around github.com.
- It's three days old. The design has held up so far, but it hasn't been through much real use yet.