Using one machine for both work and personal projects is common, but GitHub's default settings make it tricky to juggle two identities. If you've ever accidentally pushed a personal side project using your corporate email, this guide is for you.
Step 1: Separate Your SSH Keys
First, generate a unique SSH key for each account. Don't overwrite your existing one! Name them clearly, such as id_ed25519_personal and id_ed25519_work.
Next, edit your ~/.ssh/config file to define how SSH should handle different GitHub "hosts":
# Personal Account
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work Account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
Note: Ensure you've added these public keys to their respective GitHub accounts under Settings > SSH and GPG keys.
Step 2: Update Your Git Remotes
This is the "secret sauce." Instead of using the standard git@github.com, you must use the aliases you created in your SSH config.
Check your current remote:
git remote -v
Update it to point to the correct identity:
# For a personal repo
git remote set-url origin git@github-personal:username/repo.git
# For a work repo
git remote set-url origin git@github-work:org/repo.git
Step 3: Handling the VS Code Interface
While the SSH config handles the push/pull logic, the VS Code "Accounts" menu (bottom left) handles Pull Requests and Issues via the GitHub extension.
- You can sign into both accounts simultaneously.
- One account will be "active" at a time for extension features.
- Switch between them as needed; your SSH settings will keep the code commits going to the right place regardless.
git config user.email "your-work-email@company.com"