Skip to content
Back to blog
Hubert Kasperek / 2025-08-13 / DEVELOPER TOOLS

How to Use Multiple GitHub Accounts on One Computer using GitHub CLI

How I run a personal and a work GitHub account on one laptop with GitHub CLI. No SSH keys, no personal access tokens, and switching accounts takes one command.

If you keep a personal GitHub account and a company or client account on the same laptop, you’ve probably been through the SSH ritual: a key per account, host aliases in ~/.ssh/config, maybe a personal access token or two on top. It works. It also falls apart the moment you set up a new machine and can’t remember which key belongs to which account.

There’s a simpler way, and it’s the one I actually use now: GitHub CLI (gh). You log in to each account once through the browser, switch the active one with a single command, and set the commit identity per repository with git config --local. Cloning picks up whichever account is active, so you never think about tokens again.

No SSH keys, no PATs (Personal Access Tokens). Just gh.

Why GitHub CLI over SSH and PATs?

I maintained multiple SSH keys for years, then moved to PATs over HTTPS. Both approaches work, but both leave you with something to manage: keys to copy between machines, tokens that expire at the worst possible moment, a config file you wrote six months ago and no longer understand.

With gh, authentication is a browser login and the token sits in your OS keychain. There’s nothing to copy around and nothing to rotate by hand. Switching accounts stops being a small project and becomes a command you type without thinking.

Side note: GitHub Desktop still doesn’t support multiple signed-in accounts (at least when I’m writing this). If you juggle personal and work profiles, gh auth switch is the missing feature.

Setup

The whole thing is five steps:

  1. Log in to each account with gh auth login
  2. Tell Git to use gh for credentials (gh auth setup-git)
  3. In each repository, set user.name and user.email locally
  4. Switch the active account with gh auth switch
  5. Clone from the correct account with gh repo clone

If you just want the commands, grab Quick start (copy/paste) and go. The detailed guide below walks through the same flow and explains what each step actually does.

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:

  • GitHub.com
  • HTTPS
  • Login with a web browser

The CLI opens your browser, you confirm, done. Repeat for each account you use. You can check what’s configured at any point:

gh auth status

You should see every authenticated account listed under github.com.

Step 2 - Let Git use gh for credentials

Make Git ask gh for credentials on HTTPS operations:

gh auth setup-git

This sets gh as Git’s credential helper for GitHub, so pushes and pulls use the token of whichever account is currently active. If you used PATs before, this is the step that replaces them.

Step 3 - Per-repository author identity (the important bit)

Your commit author should match where the code lives. Set it locally in each repository, so a global setting never leaks your personal email into a company repo (or the other way around):

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 only affects commit metadata. It doesn’t change which account you’re authenticated as - that part is handled by gh (next step).

Tip: I keep the global identity set to my personal profile and use --local for every company and client repo.

Step 4 - Switch the active GitHub account

When you need to change accounts:

# 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 that point, gh commands and Git HTTPS operations (thanks to gh auth setup-git) use the selected account’s token.

Step 5 - Clone repos from the right account

Two options. Either clone with gh while the right 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

Or use plain git clone over HTTPS, which works the same 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 a key or token you have to manage yourself.

Reference: Commands you’ll actually use

TaskCommand
Log in to an accountgh auth login
See which accounts are authenticatedgh auth status
Show only the currently active accountgh auth status -a
Make Git use gh for HTTPSgh auth setup-git
Switch active accountgh auth switch -u <username>
Clone a repo with the active accountgh repo clone owner/repo
Set repo author identitygit config --local user.name "Name" + git config --local user.email "[email protected]"
Check current repo author namegit config --get user.name
Check current repo author emailgit config --get user.email

Common gotchas (and fixes)

  • Wrong author on commits: you forgot --local inside the repo. Set user.name and user.email there and verify with git log --format='%an <%ae>' -1.
  • Git still asks for a password: run gh auth setup-git so Git actually uses gh as the credential helper.
  • You cloned while the wrong account was active: switch with gh auth switch -u <username> and re-clone, or update the remote if that’s easier.
  • Signed commits: if your org requires them, GPG or SSH signing is configured separately from auth. Everything above still applies.
  • GitHub Enterprise: gh supports multiple hosts. Use gh auth login and gh auth switch with --hostname, or pick the host interactively.

When this setup makes sense

Use it if:

  • You work across personal and company/client repos on one machine
  • You prefer HTTPS and don’t want to manage SSH keys
  • You want commits to carry the correct identity per project
  • You switch accounts several times a day and want it to be boring

Skip it if:

  • You already have an SSH setup you like and never touch
  • You need non-interactive automation on a server (a bot account with a PAT or GitHub Actions fits better there)
  • Your organization mandates SSH-only access

FAQ

Does this store a PAT under the hood?

No. gh gets an OAuth token from the browser login and stores it in the system keychain (Keychain on macOS, for example). You never create or rotate a token yourself.

Will this break if I change laptops?

No, and this is my favorite part. Install gh, run gh auth login for each account, run gh auth setup-git, and you’re back. The per-repo user.name and user.email live inside each repository, so they travel with the code.

Can I use this alongside SSH?

Yes. You can mix approaches per repo. The point of this guide is just that you don’t need SSH for multiple accounts if you don’t want it.

Summary

Multiple GitHub accounts on one machine doesn’t have to mean SSH keys and token spreadsheets. With GitHub CLI you log in once per account, switch with one command, and keep the author identity inside each repo. When you change laptops, two commands bring the whole setup back. That’s the entire system, and it’s the reason I stopped fighting ~/.ssh/config.

Useful docs: GitHub CLI authentication and Set up Git credential helper

Thanks for reading!

I hope you found this article helpful, interesting, or useful! If you have questions, or just want to chat about web development, I'd love to hear from you.