Use Multiple GitHub Accounts on Windows

Notes

If you use more than one GitHub account on the same Windows computer, SSH host aliases let each repository use the intended key. The examples below use Git Bash and GitHub; the same pattern works with other Git hosting services that support SSH.

Create a key for each account

In Git Bash, create a separate SSH key pair for each account. Ed25519 is used in this example:

ssh-keygen -t ed25519 -C "personal@example.com" -f ~/.ssh/id_ed25519_personal
ssh-keygen -t ed25519 -C "work@example.com" -f ~/.ssh/id_ed25519_work

Add each public key (.pub) to the matching GitHub account under Settings → SSH and GPG keys → New SSH key. Keep the private key files private.

Add SSH host aliases

Create or edit ~/.ssh/config and add an entry for each account:

Host github-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_personal
    IdentitiesOnly yes

Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_work
    IdentitiesOnly yes

IdentitiesOnly yes tells SSH to use the key selected by that host entry, even if an SSH agent has other keys loaded.

Clone a repository with the right account

Use the matching alias in the SSH URL. For the personal account:

git clone git@github-personal:OWNER/REPOSITORY.git

For an existing repository, update its remote from inside the repository:

git remote set-url origin git@github-work:OWNER/REPOSITORY.git

You can test an alias with ssh -T git@github-personal or ssh -T git@github-work.

Set the commit author for each repository

SSH authentication and the author recorded in a Git commit are separate settings. Set the name and email for the current repository:

git config user.name "Your Name"
git config user.email "your-account-email@example.com"

Run these commands from the repository directory. If you want to keep your email private on GitHub, use the noreply address shown in your GitHub email settings. GitHub matches command-line commits to an account using the commit email address; changing this setting affects future commits.

See GitHub’s guides to managing multiple accounts and setting your commit email address.