GitHub
Multiple Accounts
Configuration
Version Control
Software Development

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.

Browse interview questions

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.

bash
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_work
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_personal

Add each public key to the matching GitHub account.

bash
cat ~/.ssh/id_ed25519_work.pub
cat ~/.ssh/id_ed25519_personal.pub

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.

sshconfig
1Host github-work
2  HostName github.com
3  User git
4  IdentityFile ~/.ssh/id_ed25519_work
5  IdentitiesOnly yes
6
7Host github-personal
8  HostName github.com
9  User git
10  IdentityFile ~/.ssh/id_ed25519_personal
11  IdentitiesOnly yes

Then test both aliases.

bash
ssh -T git@github-work
ssh -T git@github-personal

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.

bash
git clone git@github-work:company/backend-api.git
git clone git@github-personal:myuser/dotfiles.git

If a repository was cloned earlier with the generic host, change the remote.

bash
git remote set-url origin git@github-work:company/backend-api.git
git remote -v

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.

bash
1# inside a work repo
2git config user.name "Work Name"
3git config user.email "[email protected]"
4
5# inside a personal repo
6git config user.name "Personal Name"
7git config user.email "[email protected]"

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:

ini
1[includeIf "gitdir:~/work/"]
2  path = ~/.gitconfig-work
3
4[includeIf "gitdir:~/personal/"]
5  path = ~/.gitconfig-personal

Work-specific config:

ini
[user]
  name = Work Name
  email = [email protected]

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.

bash
1git remote -v
2git config user.name
3git config user.email
4ssh -T git@github-work

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.com instead of the SSH alias host.
  • Assuming the right SSH key automatically means the right commit author email.
  • Forgetting IdentitiesOnly yes and 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.name and user.email per repository or per directory group.
  • Run a short identity audit before pushing to avoid cross-account mistakes.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.