7 min left
0% complete
Managing Multiple GitHub Accounts on One Machine (Windows)
A Complete Step-by-Step Guide with Real Errors & Fixes
A Complete Step-by-Step Guide with Real Errors & Fixes
If you're a developer juggling a personal GitHub account and a work account, you’ve probably run into confusing issues when trying to push to repositories. Commits showing up under the wrong profile. Authentication failures. Endless password prompts.
And the worst part? There’s no “log out” button in Git.
Unlike websites, GitHub authentication happens locally on your machine. This means you can’t just “switch accounts” like you would in a browser. But once you understand how Git and SSH actually work, the solution becomes clear — and reliable.
In this guide, I’ll walk you through not just the ideal setup, but the real problems I encountered when configuring two GitHub accounts on one Windows machine — and how to fix them for good.
🔥 The Core Problem: Git Doesn’t Know Your GitHub Account
Here’s the big revelation:
Git doesn’t care about your GitHub account.
It only cares about three things:
>
- Your SSH keys
- Your remote repository URLs
- Your commit email address
If these don’t line up, you’ll get authentication errors, pushes to the wrong account, or blocked access — even if you’re “logged in” to the right account on GitHub.com.
And no — signing out of GitHub in your browser won’t help. That has zero effect on Git operations.
❌ Common Misconceptions
Before I fixed this, I believed several myths:
- “I can just log out and log back in.” → Nope.
- “Git uses my browser login.” → False.
- “If I commit with my work email, it’ll go to my work account.” → Not how it works.
The truth is: Git authentication is local, not session-based. Your SSH key and remote URL determine which account is used — not your browser or email.
✅ The Right Approach: One SSH Key Per Account
The professional solution is simple in concept:
One SSH key per GitHub account.
Each key permanently represents one identity.
This way, your machine can securely and unambiguously push to both accounts — no switching, no confusion.
Let’s walk through the setup step by step.
🧩 Step 1: Check Your SSH Folder
Open Git Bash and run:
ls ~/.sshIf you see files like id_rsa or id_ed25519, you already have SSH keys. If not, and you only see known_hosts, you’re starting fresh — great.
✅ No existing keys? Nothing's broken.
❌ Already have keys? We’ll still create new ones per account.
🔑 Step 2: Create Two SSH Keys
We’ll generate one key for your personal account and one for work.
For Your Personal Account
ssh-keygen -t ed25519 -C "personal@email.com"When prompted, save it as:
~/.ssh/id_ed25519_personalFor Your Work Account
ssh-keygen -t ed25519 -C "work@email.com"Save it as:
~/.ssh/id_ed25519_work💡 Why use `ed25519`?
It’s a modern, secure, and widely supported SSH key type. Faster and safer than olderrsakeys.
After this step, your ~/.ssh folder should contain:
id_ed25519_personal
id_ed25519_personal.pub
id_ed25519_work
id_ed25519_work.pub
known_hosts⚠️ Common Error: “No such file or directory”
Cause:
On Windows, if you're typing paths with backslashes (\) or using the wrong directory structure, ssh-keygen fails.
Fix:
Always use Git Bash (not Command Prompt or PowerShell) and use forward slashes:
/c/Users/YourName/.ssh/id_ed25519_personalGit Bash expects Unix-style paths. Stick with it, and everything works.
🔐 Step 3: Add Keys to SSH Agent
The SSH agent manages your keys and makes them available when needed.
Start the agent and add both keys:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_workVerify they’re loaded:
ssh-add -l✅ Success = two keys listed.
⚙️ Step 4: Configure SSH with Aliases (Critical!)
This is the heart of the setup. We tell SSH how to route requests based on which "host" we use.
Create or edit the file:
~/.ssh/configAdd the following:
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_workWhat This Does
- When you use
git@github-personal, SSH uses your personal key. - When you use
git@github-work, SSH uses your work key.
🧠 This is like creating custom shortcuts that map to the same server (github.com) but use different keys.
❌ Error: “ssh: Could not resolve hostname github-personal”
Cause:
The file is named config.txt instead of config.
SSH only reads a file named exactly config — no extension.
Fix:
Rename the file:
mv config.txt configOn Windows, in Git Bash:
mv ~/.ssh/config.txt ~/.ssh/config✅ Confirm it’s correct:
cat ~/.ssh/configShould display your host definitions.
🔗 Step 5: Add Public Keys to GitHub
For each account, go to:
Settings → SSH and GPG keys → New SSH key
Copy the public key content:
cat ~/.ssh/id_ed25519_personal.pubPaste it into GitHub.
📌 Key type: Choose “Authentication key”
Not “Signing key.” Signing keys are for commit signing (GPG), not pushing code.
Repeat for your work key on your work GitHub account.
🔐 Step 6: Test the SSH Connection
Now test both identities:
ssh -T git@github-personal
ssh -T git@github-workExpected output:
You've successfully authenticated, but GitHub does not provide shell access.🛑 This is not an error — it means success!
GitHub doesn’t give shell access, so this message confirms authentication works.
🚀 Step 7: Fix Your Remote URLs
Most problems happen here.
If your repos were cloned via HTTPS:
https://github.com/username/repo.gitor with the default SSH:
git@github.com:username/repo.git… then they bypass your custom SSH config and use the wrong key.
✅ Fix: Update the Remote URL
For a work repository:
git remote set-url origin git@github-work:company/repo.gitFor a personal repository:
git remote set-url origin git@github-personal:username/repo.gitVerify the Change
git remote -vYou should see:
origin git@github-work:company/repo.git (fetch)
origin git@github-work:company/repo.git (push)Now, Git knows which SSH key to use — based on the host alias.
🧾 Step 8: Set the Correct Commit Identity
Even with perfect SSH setup, your commits might show up on the wrong profile.
Why?
GitHub links commits to your email address — not your SSH key.
So you must set the correct email per repository.
For a Work Repo
git config user.email "work@company.com"
git config user.name "Your Work Name"For a Personal Repo
git config user.email "personal@email.com"
git config user.name "Your Personal Name"💡 These are local settings (per-repo).
Avoidgit config --global user.email— it forces one email everywhere.
Verify:
git config user.email❌ “How Do I Logout from GitHub?”
There’s no such thing — at least not in SSH.
| Method | How to "Logout" |
|---|---|
| HTTPS | Remove credentials from Windows Credential Manager |
| SSH | No logout — authentication is persistent |
| GitHub CLI | Run gh auth logout |
SSH keys are meant to be long-lived and trusted. The security comes from protecting your private key, not frequent logouts.
🧠 The Right Mental Model
Keep these three things in mind:
| Component | Purpose |
|---|---|
| SSH Key | Proves who you are to GitHub |
| Remote URL | Decides which account to use (via SSH host alias) |
| Commit Email | Determines which profile gets credit for the commit |
🌐 Browser login? Irrelevant.
🔑 SSH authentication? Everything.
✅ Final Push Flow
Once everything is set up, pushing is seamless:
git add .
git commit -m "Fixed issue with auth config"
git pushNo passwords. No tokens. No prompts.
Just clean, secure, account-specific access.
🎯 Final Result
With this setup:
✅ Personal repositories push under your personal account
✅ Work repositories use your work identity
✅ No accidental credential mixing
✅ No daily re-authentication
And best of all — you never have to “switch accounts” again.
This is how professional developers manage multiple GitHub identities — with precision, security, and peace of mind.