Skip to content
$ gitswitch
Nord
★ star

GitHub Account Sync

When you switch profiles, gitswitch can automatically call gh auth switch to sync your GitHub CLI account.

Terminal window
gitswitch work
# Switches git identity AND GitHub CLI account

The GitHub CLI (gh) manages separate authentication from git:

  • gh auth switch changes which GitHub account gh CLI 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.

Terminal window
gitswitch add work "Alice" alice@company.com \
--gh-user alice-work
Terminal window
gh auth status

Shows all authenticated GitHub accounts.

Terminal window
gh auth login

Authenticate a new GitHub account with gh.

When you switch to a profile with a GitHub username, gitswitch runs:

Terminal window
gh auth switch --user alice-work

Important: GitHub sync is best-effort:

  • If gh is not installed, the switch is ignored
  • If the account is not authenticated, the switch fails gracefully
  • Your git config always switches even if gh fails

Example:

Terminal window
gitswitch work
# Even if `gh auth switch` fails, your git identity is now 'work'

After switching:

Terminal window
gh auth status
# Shows the active account

If you have multiple GitHub accounts:

Terminal window
# Personal account
gitswitch add personal "Alice" alice@gmail.com \
--gh-user alice \
--ssh-key ~/.ssh/id_personal
# Work account
gitswitch add work "Alice" alice@company.com \
--gh-user alice-work \
--ssh-key ~/.ssh/id_work

Switching profiles switches both git and GitHub CLI.

If gh auth switch fails:

  1. Is gh installed?
  2. Is the account authenticated?
Terminal window
# List authenticated accounts
gh auth status
# Login to account if needed
gh auth login --with-token < token.txt
  1. Is the username correct?
Terminal window
# Check your GitHub username
gh auth status

GitHub CLI account and git identity mismatch

Section titled “GitHub CLI account and git identity mismatch”

If your GitHub account differs from git config:

Terminal window
# Check active account
gh auth status
# Check git identity
git config --global user.email

They can be different — gh commands use the GitHub account, commits use git config.

If you want them in sync:

Terminal window
# Manually switch git (if gitswitch didn't)
gitswitch work
# Manually switch GitHub (if gh auth switch failed)
gh auth switch --user alice-work

If you don’t want GitHub sync for a profile:

Terminal window
gitswitch add work "Alice" alice@company.com
# Don't pass --gh-user flag

Now switching to work changes only git identity, not GitHub CLI account.

Identity Awareness
Shell Integration
Quick Start