If you are like me, you probably have a personal GitHub account for your side projects and a separate professional account for your company. And if you’re working on a Windows machine using VS Code, you’ve likely hit the wall where Git doesn't know who you are.
I recently spent hours struggling with this. I tried running Linux commands like eval $(ssh-agent -s) in PowerShell (which didn't work), got "Permission Denied" errors, and even accidentally pushed work code using my personal email. 🤦♂️
After figuring it out, I decided to document the exact, battle-tested method to manage multiple GitHub accounts on Windows without going crazy.
Here is how to do it right.
The Concept: SSH Keys & Aliases
By default, Git pushes code as one global user. To switch between accounts, we need:
- Two separate SSH Keys (ID cards).
- A Config File that tells your computer: "If I use the alias github-work, use my Work Key."
Step 1: Generate Unique SSH Keys
Open PowerShell and create a .ssh directory if you don't have one.
mkdir $HOME\.ssh
cd $HOME\.ssh
Now, create two keys. Don't overwrite your existing default key (id_rsa). Give them specific names:
For Personal:
ssh-keygen -t ed25519 -C "personal@gmail.com" -f id_personal
For Work:
ssh-keygen -t ed25519 -C "work@company.com" -f id_work
Step 2: The "Eval" Problem (And the Windows Solution)
Most tutorials tell you to run eval $(ssh-agent -s). This command often fails or does nothing in Windows PowerShell.
Instead of fighting with the terminal, use the native Windows Service. This is better because it persists even after you restart your computer.
- Open PowerShell as Administrator.
- Run these two commands:
# Set the service to run automatically
Get-Service -Name ssh-agent | Set-Service -StartupType Automatic
# Start the service
Start-Service ssh-agent
- Now, add your keys (you can do this in a normal PowerShell window):
ssh-add $HOME\.ssh\id_personal
ssh-add $HOME\.ssh\id_work
Run ssh-add -l to confirm both keys are loaded.
Step 3: Upload Keys to GitHub
You need to introduce yourself to GitHub.
- Copy the content of your Personal Public Key (id_personal.pub).
- Go to Personal GitHub > Settings > SSH Keys > New SSH Key and paste it.
- Repeat this for your Work Public Key (id_work.pub) on your Company GitHub account.
Step 4: The Magic Config File (The Router)
This is the most important step. Create a file named config (no extension) inside your $HOME\.ssh\ folder.
Paste this configuration:
# Personal Account - Default
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_personal
# Work Account - The Custom Alias
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_work
Step 5: Cloning & Configuring Repos
Here is where the workflow changes slightly.
For Personal Projects: Clone as usual: git clone git@github.com:username/repo.git
For Work Projects: You must replace github.com with your alias github-work:
git clone git@github-work:company/repo.git
⚠️ Crucial Step: Set Your Local Identity
Once you clone the work repo, immediately run this inside the folder. If you forget this, your commits will show up as your personal user!
git config user.name "Your Work Name"
git config user.email "work@company.com"
Bonus: "Oops, I already pushed with the wrong email!"
I did this. I pushed a commit to my company repo, and it showed my personal Gmail and profile picture. Panic mode! 🚨
But you can fix it without deleting the repo.
- Fix your config first:
git config user.email "work@company.com"
- Amend the last commit: This command rewrites the last commit with your new config.
git commit --amend --reset-author --no-edit
- Force Push: Since you changed history, you need to force the update.
git push -f origin main
And just like that, your commit history is clean!
Conclusion
Setting this up takes about 10 minutes, but it saves you from endless "Permission Denied" errors and the embarrassment of mixing up identities. Once the SSH Agent service and Config file are set, everything just works in the background.
Top comments (0)