Multiple GitHub accounts on the same computer?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Using personal and work GitHub accounts on one machine is normal, but Git and SSH will happily use the wrong identity unless you configure them deliberately. The reliable setup separates two concerns: authentication and commit identity. SSH or HTTPS determines which account can access the repository. Git user.name and user.email determine who authored the commit.
Generate One SSH Key Per Account
The cleanest SSH setup uses a separate key pair for each account.
Add each public key to the matching GitHub account.
Using separate keys makes it obvious which credential belongs to which account and avoids silent cross-account reuse.
Use SSH Host Aliases to Select the Right Key
In ~/.ssh/config, define one alias per GitHub account.
Then test both aliases.
Each command should authenticate as the expected account.
Clone Repositories with the Alias, Not Plain github.com
The remote URL controls which SSH alias is used.
If a repository was cloned earlier with the generic host, change the remote.
If you forget this step, the SSH config separation exists but the repository will not use it.
Commit Identity Is a Separate Configuration Layer
Even with the correct SSH key, your commits can still carry the wrong author name and email. Set those values per repository or per directory group.
This is independent of authentication. The correct key does not automatically choose the correct commit email.
Directory-Based Auto Configuration Scales Better
If you keep work and personal repositories in separate parent directories, conditional includes are a good quality-of-life improvement.
Main Git config:
Work-specific config:
This reduces manual per-repo setup and lowers the chance of mixing identities.
HTTPS Is Possible, but SSH Is Usually Easier to Audit
You can manage multiple GitHub accounts with HTTPS tokens too, but credential helpers can make it harder to see which token is being used for which repository. SSH aliases are often easier to inspect because the remote URL itself clearly encodes the intended identity.
That does not make HTTPS wrong. It just means SSH is often the clearer multi-account workflow on one machine.
Do a Quick Identity Check Before First Push
A short audit prevents most mistakes.
That takes seconds and is much cheaper than cleaning up commits authored with the wrong email or pushing to the wrong account.
Common Pitfalls
- Cloning with
github.cominstead of the SSH alias host. - Assuming the right SSH key automatically means the right commit author email.
- Forgetting
IdentitiesOnly yesand letting the SSH agent offer unintended keys. - Using one SSH key for several accounts without a deliberate reason.
- Skipping a quick identity check before the first push.
Summary
- Separate authentication from commit identity when using multiple GitHub accounts.
- Use one SSH key and one SSH host alias per account.
- Clone or rewrite remotes so repositories actually use the correct alias.
- Set
user.nameanduser.emailper repository or per directory group. - Run a short identity audit before pushing to avoid cross-account mistakes.
Related reading
- Multiple .gitignore in subfolders
- My Git bash forgets my aliases. What can I do?
- Need to reset git branch to origin version
- New file created in Xcode 9.3, wsname.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist should it be committed?
- No property found for type... custom Spring Data repository
- No qualifying bean of type for JPA repository in Spring Boot
- No submodule mapping found in .gitmodule for a path that's not a submodule
- Non-Recursive Merge Sort
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.