Setting up multiple GitHub accounts on one computer comes down to separating three things: the name/email in your commits, the credential Git pushes with, and the SSH key it offers. The three proven configurations are: mix protocols (HTTPS for one account, SSH for the other), stay on HTTPS with one stored credential per repository (useHttpPath), or go all-SSH with one key per account and folder-based identities via includeIf. All three are the methods GitHub's own documentation teaches — full commands below. If you'd rather skip the configuration entirely, GITmaxed achieves the same result by design: add each account once, pin each repository, done.
includeIf) is the most automatic. The configuration-free path is GITmaxed.
Before anything: what decides "who you are"
| Question | Decided by | Check with |
|---|---|---|
| Whose name is on the commit? | user.name / user.email in Git config | git var GIT_AUTHOR_IDENT |
| Which account pushes over HTTPS? | The credential helper (Git Credential Manager / keychain) | git remote -v + the login you signed in with |
| Which account pushes over SSH? | The SSH key offered for the remote | ssh -T git@github.com |
Which account does gh use? | The active CLI login | gh auth status --active |
Half-configured setups are the #1 source of "pushed from the wrong account": fixing the email does not fix the credential, and vice versa.
Step 0 — folder layout and prerequisites
- Create one root folder per identity:
C:\WorkandC:\Personal(or~/work,~/personalon macOS/Linux). Every repository lives under the folder of its account — this is what all automatic methods key on. - Install current Git for Windows (ships Git Credential Manager). Run the commands in Git Bash.
- Prepare per account: an SSH key (GitHub requires one key per account — reusing a key fails with "Key already in use") and/or a personal access token (classic with
reposcope, or fine-grained per repository).
Method A — HTTPS for one account, SSH for the other (least configuration)
This is the approach GitHub's Personal account management page recommends: different protocols cannot collide, so both accounts work on one machine with almost no setup.
- Account A (work): keep HTTPS. The first time Git asks, sign in as the work account — Git Credential Manager stores that login for
https://github.com. - Account B (personal): add an SSH key to the personal account and clone with the SSH URL:
ssh-keygen -t ed25519 -C "personal@example.com" -f ~/.ssh/id_ed25519_personal
# upload the .pub file: GitHub → personal account → Settings → SSH and GPG keys
git clone git@github.com:personal-user/repo.git
HTTPS remotes keep using the stored work login; SSH remotes authenticate with the personal key. Works in the terminal and in desktop clients — an SSH-clone repo authenticates independently of whatever account the GUI is signed into.
Method B — HTTPS only, one stored credential per account
If your network forces HTTPS, make the credential manager distinguish accounts by repository instead of by host:
git config --global credential.https://github.com.useHttpPath true
# optional: pin a default login per host/folder
git config --global credential.https://github.com.username work-login
- Create one personal access token per account.
- Clone normally; on the first push per repository, sign in as the account that owns it.
- GCM now caches one login per repository URL — work repos push as work, client repos as client, permanently.
Wrong login got saved? Clear it and re-authenticate:
echo "protocol=https
host=github.com" | git credential-manager erase
# classic Windows Credential Manager:
cmdkey /delete:LegacyGeneric:target=git:https://github.com
Method C — SSH only, fully automatic per-folder identities
The power setup: one key per account, host aliases with pinned identities, and folder-based Git config. After this, a plain git push anywhere always uses the right identity.
1. SSH host aliases
# ~/.ssh/config
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
IdentitiesOnly yes is mandatory — without it the agent may offer the wrong key first. Upload each .pub to the matching account and test:
ssh -i ~/.ssh/id_ed25519_work -o IdentitiesOnly=yes -T git@github.com
# Hi work-user! You've successfully authenticated...
2. Folder-based identity with includeIf
# ~/.gitconfig
[includeIf "gitdir/i:C:/Work/"]
path = ~/.gitconfig-work
[includeIf "gitdir/i:C:/Personal/"]
path = ~/.gitconfig-personal
# ~/.gitconfig-work
[user]
name = Work Name
email = me@company.com
[core]
sshCommand = ssh -i ~/.ssh/id_ed25519_work -o IdentitiesOnly=yes
# ~/.gitconfig-personal
[user]
name = Personal Name
email = me@example.com
[core]
sshCommand = ssh -i ~/.ssh/id_ed25519_personal -o IdentitiesOnly=yes
Windows note: gitdir/i: (case-insensitive) plus the trailing slash is the correct form. Optional URL rewrite so you can paste plain GitHub URLs into C:\Work repos:
# in ~/.gitconfig-work
[url "git@github-work:"]
insteadOf = git@github.com:
Verify before trusting the setup
cd C:/Work/some-repo
git remote -v # https vs ssh — which half applies
git var GIT_AUTHOR_IDENT # identity that will be committed
ssh -T git@github.com # which account the active key belongs to
git log -1 --format='%an <%ae>' # author of the latest commit
Test push, then confirm the commit badge on github.com matches the intended account.
Common mistakes
- Reusing one SSH key on both accounts — GitHub blocks it; one key per account.
- Changing email but not the push credential — right-looking commits, wrong-account pushes.
- Missing
IdentitiesOnly yes— agent offers the wrong key; "Permission denied (publickey)". - Opening folders via a different path (mapped drive, symlink) —
includeIfsilently stops matching. - No folder discipline — without one tree per account, nothing can know which identity you meant.
- Pushing internal code to a public personal repo — GitHub's own docs warn about this; keep trees clearly separated.
The configuration-free alternative: GITmaxed
Everything above is correct terminal engineering — and all of it exists because desktop tools assume one account. GITmaxed is a free Windows Git client (a GitHub Desktop fork) that makes the configuration unnecessary:
- Add every account in Preferences → Accounts — all stay signed in; there is no "active account" to forget.
- Open a repository → account picker → pin it to its account. The binding persists.
- Commits get the bound account's identity; pushes, pulls, and PRs authenticate as that account — no
includeIf, no key juggling, nouseHttpPath.
Use the manual methods if you live in the terminal and enjoy controlling every line. Use GITmaxed if you want the outcome — correct identity on every push — without maintaining the machinery.
Related questions answered (the same queries, one by one)
How do I use multiple GitHub accounts on one PC?
Folders per account + one credential per account (SSH key or token) + per-folder identity. Methods A–C above; or GITmaxed for the no-config route.
How do I clone repositories from two GitHub accounts on the same machine?
Just clone with the right URL shape per account — SSH for the key-backed account, HTTPS for the credential-backed one. The folder you clone into decides the commit identity (with includeIf configured).
What is the Git config for multiple GitHub accounts?
Two pieces: credential.https://github.com.useHttpPath true for HTTPS credentials, and [includeIf "gitdir/i:…"] blocks loading per-account .gitconfig files with user.* and core.sshCommand.
How does SSH config handle multiple GitHub accounts?
One Host alias per account with its own IdentityFile and IdentitiesOnly yes; optionally rewrite git@github.com: to the alias with url.insteadOf.
Do I need two computers or two Windows users for two GitHub accounts?
No — one machine, one OS user is enough with any method here.
Is there an app that sets this up automatically?
Yes — GITmaxed: add accounts, pin repositories, and every operation uses the correct identity without any of the configuration on this page.
No comments:
Post a Comment