How to Use Multiple GitHub Accounts on One Computer using GitHub CLI
Use GitHub CLI to manage multiple GitHub accounts on one machine — no SSH keys or PATs. Per‑repo identity, fast account switching, hassle‑free cloning.
If you've ever juggled a personal GitHub account and a company or client GitHub account on the same laptop, you've probably fallen down the rabbit hole of SSH keys, config files, and personal access tokens. That works — but it's fiddly, hard to remember, and easy to break when you switch machines.
Here's the simpler way I now recommend: use GitHub CLI (gh
). It lets you:
git config --local
In short: no SSH keys, no PATs (Personal Access Tokens) — just gh
.
Why GitHub CLI over SSH and PATs (Personal Access Tokens)?
Let me be honest: I used to maintain multiple SSH keys with ~/.ssh/config
, then switched to PATs (Personal Access Tokens) for HTTPS. Both approaches work, but they add a maintenance burden and are brittle across machines. With gh
, authentication happens via your browser and the token lives securely in your OS keychain. Swapping accounts becomes muscle memory rather than a mini‑tutorial every time.
The goal is frictionless context switching: pick the account, set the repo identity, do the work.
Side note: GitHub Desktop doesn’t support multiple signed‑in accounts for some reason (at least at the time of this writing). If you juggle personal and work profiles, GitHub CLI gives you first‑class multi‑account switching via gh auth switch
.
Setup
You'll set up two (or more) GitHub accounts on a single device and switch between them in seconds:
gh auth login
gh
for credentials (gh auth setup-git
)user.name
and user.email
locallygh auth switch
gh repo clone
Short on time? Grab Quick start — copy/paste and go. Want the why behind each command? Detailed guide walks through the same flow with context and gotchas.
Quick start (copy/paste)
First install GitHub CLI
# 1) Log into Account A
gh auth login
# Follow the prompts: GitHub.com → HTTPS → Login with a web browser
# 2) Make sure Git asks gh for credentials
gh auth setup-git
# 3) (Optional) Log into Account B too
gh auth login
# 4) See which accounts are configured
gh auth status
# 5) Switch the active account (by username)
gh auth switch -u your-company-username
# 6) Clone a repo while the right account is active
gh repo clone owner/repo
# ^ Sidenote: you can also just enter the repository url
# instead of owner/repo format
# 7) Inside each repo, set the author identity (local only)
git config --local user.name "Your Name"
git config --local user.email "[email protected]"
That’s the entire workflow. No ~/.ssh/config
gymnastics.
Detailed guide
Step 1 — Install and log in with GitHub CLI
Install GitHub CLI (gh
) following the official instructions for your OS. Then run:
gh auth login
Pick:
CLI will open your browser, you confirm, and you’re done. Repeat for each account you use (personal, work, client). You can verify your setup:
gh auth status
You should see all authenticated accounts listed for github.com
.
Step 2 — Let Git use gh
for credentials
Make Git use gh
for HTTPS so pushes use the right account:
gh auth setup-git
This configures Git’s credential helper so GitHub HTTPS operations delegate to gh
under the hood. If you ever used PATs before, this avoids storing or rotating them manually.
Step 3 — Per‑repository author identity (the important bit)
Your Git author identity should reflect where the code belongs. Keep it local to each repository so global settings never leak between personal and company projects.
cd /path/to/your/repo
# Set author identity only for THIS repo
git config --local user.name "Your Name"
git config --local user.email "[email protected]"
# Verify
git config --get user.name
git config --get user.email
This affects commit metadata only; it doesn’t change which account you’re authenticated as. Authentication is handled by gh
(next section).
Tip: Keep global identity empty or set it to your personal profile; rely on --local
for company/client repos.
Step 4 — Switch the active GitHub account
When you need to move between accounts, switch the active one:
# List status (who’s active now?)
gh auth status
# Switch by username for github.com
gh auth switch -u your-company-username
# Or interactively if you prefer
gh auth switch
From now on, your gh
commands and GitHub HTTPS operations (thanks to gh auth setup-git
) use the selected account’s token.
Step 5 — Clone repos from the right account
Two easy options:
1) Use gh
to clone while the correct account is active:
gh auth switch -u personal-username
gh repo clone myusername/dotfiles
# ^ Sidenote: you can also just enter the repository url
# instead of owner/repo format
gh auth switch -u work-username
gh repo clone my-company/internal-tool
# ^ Sidenote: you can also just enter the repository url
# instead of owner/repo format
2) Or use standard git clone
over HTTPS after gh auth setup-git
:
gh auth switch -u work-username
git clone https://github.com/my-company/internal-tool.git
Either way, the credential comes from the active gh
session — not from an SSH key or a PAT you have to manage.
Reference: Commands you’ll actually use
Task | Command |
---|---|
Log in to an account | gh auth login |
See which accounts are authenticated | gh auth status |
Show only the currently active account | gh auth status -a |
Make Git use gh for HTTPS | gh auth setup-git |
Switch active account | gh auth switch -u <username> |
Clone a repo with the active account | gh repo clone owner/repo |
Set repo author identity | git config --local user.name "Name" + git config --local user.email "[email protected]" |
Check current repo author name | git config --get user.name |
Check current repo author email | git config --get user.email |
Common gotchas (and fixes)
user.name
and user.email
with --local
inside each repo. Verify with git log --format='%an <%ae>' -1
.gh auth setup-git
so Git uses gh
as the credential helper for GitHub over HTTPS.gh auth switch -u <username>
and re‑clone, or update the remote if appropriate.gh
supports multiple hosts. Use gh auth login
and gh auth switch
with the appropriate --hostname
or choose it interactively.My Recommendation
When to Use This Setup
Perfect for:
Skip this for:
FAQ
Does this store a PAT under the hood?
No. gh
uses an OAuth token scoped via your browser login and stores it securely (Keychain on macOS, etc.). You don’t create or rotate PATs yourself.
Will this break if I change laptops?
Just reinstall gh
, run gh auth login
for your accounts, and gh auth setup-git
. Your per‑repo user.name
/user.email
live in each repository, so they carry with the repo.
Can I use this alongside SSH?
Yes. You can mix approaches per repo, but the point of this guide is that you don’t need SSH for multiple accounts if you don’t want it.
Summary
Managing multiple GitHub accounts doesn’t have to mean wrangling SSH keys or memorizing PATs. With GitHub CLI, you log in once per account, switch the active session in seconds, keep author identity local to each repo, and clone confidently from the right profile. Fewer moving parts, fewer surprises — and the setup survives across machines.
Useful docs: GitHub CLI authentication · Set up Git credential helper