If you work with multiple projects or clients, you may need to manage multiple GitHub accounts in Visual Studio Code. Many developers face issues like authentication errors, push failures, or difficulty switching between accounts.
In this guide, you will learn:
- How to use multiple GitHub accounts in VS Code using SSH keys
- How to switch GitHub accounts without logging out
- How to fix push errors after changing accounts
1 How to Use Multiple GitHub Accounts in VS Code (Best Method)
The best way to use multiple GitHub accounts is by using SSH keys. This allows you to manage multiple accounts without repeatedly logging in and out.
💡 Why SSH Keys? SSH keys provide a secure, password-free authentication method. Each key is unique to an account, so Git automatically picks the correct credentials based on your configuration.
1 Generate SSH Keys for Each Account
Open the VS Code terminal or Command Prompt and generate a key for each account.
For your first GitHub account (personal):
ssh-keygen -t ed25519 -C "personal@email.com"
When prompted for the file location, save the key as:
id_ed25519_personal
For your second GitHub account (work):
ssh-keygen -t ed25519 -C "work@email.com"
Save the key as:
id_ed25519_work
⚠ Important: Use unique and descriptive filenames for each key. If you accept the default filename, the second key will overwrite the first one.
2 Add SSH Keys to the SSH Agent
Start the SSH agent and add both keys:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work
This registers both keys so they are available for authentication.
3 Add SSH Keys to GitHub
Copy the public key for the first account:
cat ~/.ssh/id_ed25519_personal.pub
Then add it to GitHub:
- Go to GitHub.com and log in with the first account
- Open Settings
- Click SSH and GPG keys
- Click New SSH Key
- Paste the copied key and give it a descriptive title
Repeat the same steps for the second account — log in with the second GitHub account and add the
id_ed25519_work.pub key.
4 Configure SSH Config File
This is the most important step. Open (or create) the SSH config file:
~/.ssh/config
Add the following configuration:
# Personal GitHub Account
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work GitHub Account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
💡 How it works: The Host alias acts as a shortcut. When you use
github-personal in a Git URL, SSH automatically uses the personal key. When you use
github-work, it uses the work key. Both still connect to github.com — the alias
just tells SSH which identity to use.
5 Clone Repositories Using the Correct Account
Now use the host alias instead of github.com when cloning:
For personal projects:
git clone git@github-personal:username/repository.git
For work projects:
git clone git@github-work:username/repository.git
Now both GitHub accounts will work on the same computer — no conflicts, no repeated logins.
💡 Existing Repositories: If you already cloned a repository using HTTPS, you can switch it
to the correct SSH host by updating the remote URL:
git remote set-url origin git@github-work:username/repository.git
2 How to Switch GitHub Accounts Without Logging Out
If you do not want to use SSH keys, you can switch accounts by changing Git configuration per project. This is a simpler approach for quick switching.
Navigate to your project folder in the terminal and run:
git config user.name "Your Name"
git config user.email "your-email@example.com"
For example:
git config user.name "Aio Crafters"
git config user.email "aiocrafters@gmail.com"
This applies the Git identity only to the current project, not globally. Your other projects remain unaffected.
Verify the configuration using:
git config --list
⚠ Note: This method only changes the commit identity (name and email shown in commits). For authentication (push/pull), you will still need to handle credentials separately — either through Credential Manager or by reauthenticating in VS Code.
📊 SSH Keys vs. Per-Project Config — Which Should You Use?
| Feature | SSH Keys | Per-Project Config |
|---|---|---|
| Setup effort | One-time setup | Per project |
| Account switching | Automatic | Manual |
| Authentication | Key-based (no passwords) | Credential Manager |
| Best for | Regular multi-account use | Occasional switching |
| Security | High (key pair) | Medium (stored tokens) |
3 How to Fix Push Errors After Changing GitHub Accounts
After changing GitHub accounts, developers often encounter errors like:
remote: Permission to repository denied
fatal: Authentication failed
These errors usually happen because Git is still using old cached credentials. Here are three solutions:
🔧 Solution 1: Remove Old Credentials
- Open the Start Menu and search for Credential Manager
- Go to Windows Credentials
- Find and remove the following entries:
git:https://github.comgithub.com
- Try pushing again — Git will prompt you to authenticate with the new account
🔧 Solution 2: Update Remote Repository URL
Sometimes the repository still points to the old account. Check the remote URL:
git remote -v
If it points to the wrong account, update it:
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
For example:
git remote set-url origin https://github.com/aiocrafters/myproject.git
🔧 Solution 3: Reauthenticate GitHub in VS Code
- Press
Ctrl + Shift + Pto open the Command Palette - Search for GitHub: Sign In
- Log in with the correct account
VS Code will reconnect to GitHub with the new credentials and future pushes should work correctly.
📋 Quick Troubleshooting Reference
| Problem | Cause | Solution |
|---|---|---|
Permission denied |
Old credentials cached | Remove from Credential Manager |
Authentication failed |
Wrong account signed in | Reauthenticate via Command Palette |
| Pushes go to wrong repo | Remote URL points to old account | Update with git remote set-url |
| Commits show wrong name | Git config not updated | Set local git config user.name |
| SSH key not recognized | Key not added to agent | Run ssh-add with key path |
🔑 Developer Tip: Many professional developers maintain separate GitHub accounts for
open-source projects, freelance work, and company repositories. Learning how to manage
multiple accounts will make your workflow much more efficient. Consider organizing your projects into
separate directories (e.g., ~/personal/ and ~/work/) and using Git
conditional includes to automatically apply the correct identity based on the directory.
✅ Final Thoughts
Managing multiple GitHub accounts is a common requirement for modern developers. Using SSH keys is the most reliable and professional approach, as it allows you to switch accounts seamlessly without logging out.
However, if you prefer a simpler setup, using project-level Git configuration can also work effectively for occasional switching.
By properly configuring your Git identity and authentication methods, you can avoid push errors and maintain a smooth development workflow in Visual Studio Code.
Master your Git workflow, and switching between multiple GitHub accounts will become second nature.
