The short answer
Since gh 2.40, the GitHub CLI keeps several accounts per host. Add the second one with gh auth login, list both with gh auth status, and switch with gh auth switch --hostname github.com --user sam-acme. With exactly two accounts, plain gh auth switch swaps to the other one. The active account is global: every terminal and every repo uses it until you switch again, so check gh auth status before gh pr create.
On this page
Check your gh version
gh --versionOlder versions keep one account per host, and logging in again replaces it. Update with brew upgrade gh if you installed it with Homebrew, or download the latest release from cli.github.com.
Log in to a second account
gh auth login --hostname github.comChoose your preferred protocol and sign in through the browser as the second account. gh adds it next to the first instead of replacing it, and makes it the active one.
See which account is active
gh auth statusgithub.com
✓ Logged in to github.com account sam-acme (keyring)
- Active account: true
- Git operations protocol: ssh
✓ Logged in to github.com account samdev (keyring)
- Active account: false
- Git operations protocol: sshFor scripts, gh api user --jq .login prints just the active account's name.
Switch accounts
gh auth switch --hostname github.com --user samdev--hostname matters when you also use a GitHub Enterprise Server host; without it gh asks which host you mean if there's more than one. With exactly two accounts on one host, gh auth switch on its own swaps to the other.
What switching changes, and what it doesn't
| Action | Uses the active gh account? |
|---|---|
gh pr create, gh issue, gh repo clone, gh api | Yes |
git push over HTTPS, after gh auth setup-git | Yes: Git asks gh for the login |
git push over SSH | No: the SSH key decides the account |
| The email in your commits | No: that's user.email in Git's config |
gh pr create,gh issue,gh repo clone,gh api- Uses the active gh account?
- Yes
git pushover HTTPS, aftergh auth setup-git- Uses the active gh account?
- Yes: Git asks gh for the login
git pushover SSH- Uses the active gh account?
- No: the SSH key decides the account
The email in your commits
- Uses the active gh account?
- No: that's
user.emailin Git's config
Use a different account per folder
gh has no setting per folder, but it reads GH_TOKEN from the environment before its stored accounts. With a tool such as direnv, a work folder can set it from the stored work login:
export GH_TOKEN=$(gh auth token --hostname github.com --user sam-acme)Every program started from that shell can read the token, so keep this to folders you trust, and don't commit the .envrc with a token written into it.
Log out of one account
gh auth logout --hostname github.com --user samdevThe faster way: GitHub CLI account switcher in iKnowMyMac
iKnowMyMac shows the active gh account for each host in the menu bar popover and on its Git screen, and switches it by running gh auth switch for you. It never reads or stores a token.