GitHub Account Sync
How gitswitch integrates with the GitHub CLI
This page covers the --gh-user flag — what it does when you switch profiles and how it behaves when gh is unavailable.
What it does
When you switch to a profile that has a GitHub username, gitswitch runs:
gh auth switch --user alice-workThis changes which GitHub account gh CLI commands operate under — creating PRs, listing issues, fetching notifications, and so on.
Add a profile with a GitHub username
gitswitch add work "Alice Smith" alice@company.com \
--gh-user alice-workThe value passed to --gh-user must match a username that is already authenticated in gh:
gh auth status
# Shows all authenticated accountsIf the account is not yet authenticated:
gh auth login
# Follow the prompts to authenticate the accountBehavior when gh is unavailable
The GitHub switch is best-effort. If gh is not installed, or the specified account is not authenticated, gitswitch prints a warning but still completes the profile switch:
warning: gh auth switch --user alice-work: exec: "gh": executable file not found in $PATH
✓ Switched to 'work' — Alice Smith <alice@company.com>Steps 1–4 (git config writes) always execute. Step 5 (gh auth switch) is advisory only.
Profiles without GitHub sync
If you don't pass --gh-user, switching that profile leaves the active gh account unchanged:
gitswitch add internal "Alice Smith" alice@internal.corp
# No --gh-user — gh account is not touched when switching to 'internal'Using gh CLI with multiple accounts
# Switch to personal profile (includes --gh-user alice)
gitswitch personal
gh repo list
# Lists repos owned by alice
# Switch to work profile (includes --gh-user alice-work)
gitswitch work
gh pr create --title "Fix" --body "..."
# Creates PR as alice-workVerify active GitHub account
gh auth statusgithub.com
✓ Logged in to github.com account alice-work (keyring)
- Active account: trueTroubleshooting
gh auth switch fails silently
Run it manually to see the error:
gh auth switch --user alice-workCommon causes:
- Account not authenticated (
gh auth login) - Username typo in the profile (check with
gh auth status) ghnot installed
gh account and git identity are out of sync
This is expected when you use profiles without --gh-user. The two are independent:
gh auth status # shows GitHub API account
gitswitch current # shows git commit identityTo resync manually:
gh auth switch --user alice-work