Managing Multiple GitHub Accounts
As developers, it’s common to juggle two GitHub accounts — one for work (e.g., akhil@<COMPANY_NAME>.com
) and one for personal projects (e.g., akhil@gmail.com
).
The challenge?
- Git commits end up with the wrong email.
-
git push
gets rejected because the wrong GitHub account is used. - Constantly logging in/out is frustrating.
In this post, I’ll walk you through how to configure Git + SSH to cleanly separate accounts so that your work and personal projects never interfere with each other.
🔎 The Problem I Faced
On my work laptop:
- Git was configured with my work email globally.
- My repos were cloned using HTTPS, which always authenticated via my company GitHub account.
When I tried pushing code to my personal GitHub repo, I got this error:
remote: Permission to d-akhil-kumar/log-panda.git denied to akhil-kumar-company-git.
fatal: unable to access 'https://github.com/d-akhil-kumar/log-panda.git/': The requested URL returned error: 403
GitHub was picking the wrong account (akhil-kumar-company-git
from work), while I needed my personal account (d-akhil-kumar
).
✅ The Solution: Separate SSH Keys and Git Configs
1. Generate a Personal SSH Key
I already had a company (default) SSH key (~/.ssh/id_rsa
), so I created a new one for my personal account:
ssh-keygen -t ed25519 -C "your-personal-email@example.com" -f ~/.ssh/id_ed25519_personal
Now I have:
-
~/.ssh/id_rsa
→ company key -
~/.ssh/id_ed25519_personal
→ personal key
2. Add Keys to the SSH Agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa # company
ssh-add ~/.ssh/id_ed25519_personal # personal
3. Add the Public Key to GitHub
Copy the personal key:
cat ~/.ssh/id_ed25519_personal.pub
Go to GitHub → Settings → SSH and GPG keys → New SSH key and paste it.
4. Configure SSH for Multiple Accounts
Edit (or create) ~/.ssh/config
:
# Company GitHub
Host github.com-company
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Personal GitHub
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
This tells SSH which key to use based on the alias (github.com-company
or github.com-personal
).
5. Update Git Remotes
Inside a personal repo, update the remote URL:
git remote set-url origin git@github.com-personal:your-username/your-repo.git
For a company repo:
git remote set-url origin git@github.com-company:company-org/repo-name.git
Check with:
git remote -v
6. Test the Connection
For personal:
ssh -T git@github.com-personal
For company:
ssh -T git@github.com-company
Both should greet you with the correct account username 🎉
7. Set Git Commit Identity Per Repo
Inside a personal repo:
git config user.name "Your Name"
git config user.email "your-personal-email@example.com"
Inside a company repo:
git config user.name "Your Name"
git config user.email "your-work-email@<COMPANY_NAME>.com"
Now, commits show up under the right account.
⚡ Bonus: Auto-Switch Identities
If you keep repos in separate folders (~/work/
and ~/personal/
), Git can auto-switch your email:
Edit ~/.gitconfig
:
[user]
name = Your Name
email = your-personal-email@example.com
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-company
Create ~/.gitconfig-company
:
[user]
name = Your Name
email = your-work-email@<COMPANY_NAME>.com
Now you never need to run git config
manually again. 🚀
🎯 Final Result
- Personal repos → push with personal GitHub account and personal email
- Company repos → push with company GitHub account and company email
- No more 403 errors or wrong commit authorship
🙌 Conclusion
Managing multiple GitHub accounts doesn’t have to be painful.
With separate SSH keys and smart Git config, you can seamlessly switch between personal and work repos without conflicts.
💡 Have you set up multiple GitHub accounts on your machine? Did you use SSH, HTTPS, or another trick? Let me know in the comments!
Top comments (0)