VS Code Multi-GitHub Setup Guide

vscode github ssh windows development

Cleanly separate Personal GitHub (github.com) and GitHub Enterprise on Windows 11, using SSH keys and VS Code profiles.


Overview

ComponentPersonalWork
VS Code ProfileSettings Sync ON (GitHub.com)Settings Sync OFF (Enterprise)
SSH Keyid_ed25519_personalid_ed25519_work
Git Identity~/.gitconfig-personal~/.gitconfig-work
FolderC:\dev\personalC:\dev\work

Prerequisites

  • Windows 11
  • Git for Windows installed (includes OpenSSH)
  • VS Code installed
  • GitHub.com account (personal) + GitHub Enterprise account

Create Folder Layout

mkdir C:\dev\work
mkdir C:\dev\personal

Create SSH Keys

ssh-keygen -t ed25519 -C "you@company.com" -f $env:USERPROFILE\.ssh\id_ed25519_work
ssh-keygen -t ed25519 -C "you@gmail.com" -f $env:USERPROFILE\.ssh\id_ed25519_personal

Upload public keys:

  • id_ed25519_work.pub to Enterprise GitHub
  • id_ed25519_personal.pub to GitHub.com

Start SSH Agent

Start-Service ssh-agent
# (Optional admin-only)
# Set-Service ssh-agent -StartupType Automatic

SSH Config

Edit C:\Users\<you>\.ssh\config:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_personal
  IdentitiesOnly yes
 
Host github.mycompanyname.com
  HostName github.mycompanyname.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes

Test Connection

ssh -T git@github.com
ssh -T git@github.mycompanyname.com

Fix known_hosts Permission Errors

$me  = (cmd /c whoami)
$ssh = "$env:USERPROFILE\.ssh"
$kh  = "$ssh\known_hosts"
 
icacls $ssh /grant:r ("{0}:(F)" -f $me) "SYSTEM:(F)"
cmd /c takeown /F "$kh"
icacls $kh /grant:r ("{0}:(F)" -f $me) "SYSTEM:(R)"
attrib -R "$kh"

Git Identity Per Directory

Edit C:\Users\<you>\.gitconfig:

[user]
    name = Default User
    email = default@example.com
 
[includeIf "gitdir:C:/dev/work/"]
    path = ~/.gitconfig-work
 
[includeIf "gitdir:C:/dev/personal/"]
    path = ~/.gitconfig-personal

Create separate config files:

# ~/.gitconfig-work
[user]
    name = Work Name
    email = you@company.com
 
# ~/.gitconfig-personal
[user]
    name = Personal Name
    email = you@gmail.com

Clone Repos

# Work
cd C:\dev\work
git clone git@github.mycompanyname.com:Org/repo.git
 
# Personal
cd C:\dev\personal
git clone git@github.com:user/repo.git

VS Code Profiles

ProfileSettings SyncSign In To
PersonalONGitHub.com
WorkOFFEnterprise

Assign profiles to workspaces in VS Code.


Validate

git remote -v
git config user.email

Troubleshooting

IssueSolution
Unprotected key warningsFix key ACLs - only you + SYSTEM Read
known_hosts permission errorsMake known_hosts writable
ssh-agent auto-start deniedRun Set-Service line in admin shell only