Connect Multiple GitHub Accounts
Effortlessly Manage Multiple GitHub Accounts in VSCode with SSH 🚀
Tired of logging in and out of GitHub just to switch accounts? It’s a hassle! 😩
💡 One-Time SSH Setup = Seamless Switching!
You might have tried solutions that require custom domain names for each account, but they come with problems:
❌ You must remember different domain names while cloning.
❌ You have to manually update git config files.
🔧 In this guide, we automate everything for you—no more manual tweaks!
🛠 Step-by-Step Guide
1️⃣ Open Git Bash & Navigate to .ssh
cd ~/.ssh
2️⃣ Check for Existing SSH Keys .ssh
ls -al ~/.ssh
If you already have an SSH key (.pub file), you can use it. Otherwise, generate a new one.
3️⃣ Generate New SSH Keys
Execute the following commands one by one:
ssh-keygen -t ed25519 -C "personal_email@example.com" -f ~/.ssh/<personal_github_username>ssh-keygen -t ed25519 -C "company_email@example.com" -f ~/.ssh/<company_github_username>
Flags:
- -C: Comment to identify the key
- -f: Filename to save the key When prompted for a passphrase, leave it empty and press Enter.
4️⃣ Start the SSH Agent
eval `ssh-agent -s`
You should see an output like: Agent pid 1576
5️⃣ Add SSH Keys to SSH Agent
ssh-add ~/.ssh/personal_github_usernamessh-add ~/.ssh/company_github_username
6️⃣ Add Public SSH Keys to GitHub
Copy the public keys and add them to GitHub → Settings → SSH Keys or GitHub SSH Keys.
code ~/.ssh/personal_github_username.pubcode ~/.ssh/company_github_username.pub
7️⃣ Create & Configure SSH config File
Copy the public keys and add them to GitHub → Settings → SSH Keys or GitHub SSH Keys.
touch ~/.ssh/configcode ~/.ssh/config
Paste the following content:
Host * IgnoreUnknown AddKeysToAgent,UseKeychain AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/<personal_github_username> # Default key (You can also use company key)
This configuration allows automatic SSH key selection without needing custom domains.
8️⃣ Set Up Git Config for Different Accounts
Navigate to the home directory and create configuration files:
cd ~touch .gitconfigtouch .gitconfig.companytouch .gitconfig.personal
Edit .gitconfig and add:
[includeIf "gitdir:C:/Users/<user_name>/Personal/"]path = ~/.gitconfig.personal
[includeIf "gitdir:C:/Users/<user_name>/Company/"]path = ~/.gitconfig.company
[core]excludesfile = ~/.gitignore
Edit .gitconfig.company:
[user]email = your_company_email@example.comname = Your Name
[github]user = "company_github_username"
[core]sshCommand = "ssh -i ~/.ssh/company_github_username"
Edit .gitconfig.personal:
[user]email = your_personal_email@example.comname = Your Name
[github]user = "personal_github_username"
[core]sshCommand = "ssh -i ~/.ssh/personal_github_username"
This setup ensures that the correct SSH key is automatically used based on the folder location.
✅ Testing Your Setup
Now, you can clone repositories without worrying about switching accounts manually.
git clone git@github.com:your-personal-username/test.git # Personalgit clone git@github.com:your-company-username/test.git # Company
This Markdown file is ready to be copied and pasted into your Astro documentation! 🚀