GitHub Account Sync
What it does
Section titled “What it does”When you switch profiles, gitswitch can automatically call gh auth switch to sync your GitHub CLI account.
gitswitch work# Switches git identity AND GitHub CLI accountWhy you need this
Section titled “Why you need this”The GitHub CLI (gh) manages separate authentication from git:
gh auth switchchanges which GitHub accountghCLI commands operate under- It does NOT change your git commit identity
- If you forget to switch in
gh, you might create a PR or issue from the wrong account
gitswitch can handle both in one command.
Add profile with GitHub username
Section titled “Add profile with GitHub username”gitswitch add work "Alice" alice@company.com \ --gh-user alice-workList GitHub accounts
Section titled “List GitHub accounts”gh auth statusShows all authenticated GitHub accounts.
gh auth loginAuthenticate a new GitHub account with gh.
How it works
Section titled “How it works”When you switch to a profile with a GitHub username, gitswitch runs:
gh auth switch --user alice-workBehavior
Section titled “Behavior”Important: GitHub sync is best-effort:
- If
ghis not installed, the switch is ignored - If the account is not authenticated, the switch fails gracefully
- Your git config always switches even if
ghfails
Example:
gitswitch work# Even if `gh auth switch` fails, your git identity is now 'work'Verify account
Section titled “Verify account”After switching:
gh auth status# Shows the active accountMultiple GitHub accounts
Section titled “Multiple GitHub accounts”If you have multiple GitHub accounts:
# Personal accountgitswitch add personal "Alice" alice@gmail.com \ --gh-user alice \ --ssh-key ~/.ssh/id_personal
# Work accountgitswitch add work "Alice" alice@company.com \ --gh-user alice-work \ --ssh-key ~/.ssh/id_workSwitching profiles switches both git and GitHub CLI.
Troubleshooting
Section titled “Troubleshooting”gh auth switch fails
Section titled “gh auth switch fails”If gh auth switch fails:
- Is
ghinstalled? - Is the account authenticated?
# List authenticated accountsgh auth status
# Login to account if neededgh auth login --with-token < token.txt- Is the username correct?
# Check your GitHub usernamegh auth statusGitHub CLI account and git identity mismatch
Section titled “GitHub CLI account and git identity mismatch”If your GitHub account differs from git config:
# Check active accountgh auth status
# Check git identitygit config --global user.emailThey can be different — gh commands use the GitHub account, commits use git config.
If you want them in sync:
# Manually switch git (if gitswitch didn't)gitswitch work
# Manually switch GitHub (if gh auth switch failed)gh auth switch --user alice-workDisabling GitHub sync
Section titled “Disabling GitHub sync”If you don’t want GitHub sync for a profile:
gitswitch add work "Alice" alice@company.com# Don't pass --gh-user flagNow switching to work changes only git identity, not GitHub CLI account.