Guide / Log in to both accountsStep 1 of 5
Log in to two GitHub accounts with gh
The GitHub CLI (gh, version 2.40+) keeps several accounts logged in side by side. You log in once per account, then switch with one command.
#Personal account
In your browser, sign in to GitHub as your personal account.
In the terminal:
gh auth loginAnswer the questions:
Question Answer Where do you use GitHub? GitHub.comPreferred protocol for Git operations? HTTPSAuthenticate Git with your GitHub credentials? YesHow would you like to authenticate? Login with a web browsergh shows a code like
ABCD-1234and copies it for you. Press Enter.The browser opens github.com/login/device. Paste the code, click Continue, then Authorize.
The terminal prints
Logged in as you-personal.
#Work account
In the browser, sign out of GitHub and sign in as your work account. (Or open the link from step 5 in a private window.)
Run the same command again. It adds the account and keeps the first one:
gh auth login
#Finish
gh auth setup-git
gh auth statusgh auth status should list both accounts. One of them says Active account: true. That is the one Git uses to push and pull right now.
To change it:
gh auth switch # pick from a list
gh auth switch -u you-work # or name the accountBrowser didn't open? Copy the link into the browser yourself. To fix it for next time:
gh config set browser brave(use your browser's command name).