Using Multiple GitHub Accounts on Windows

Using Multiple GitHub Accounts on Windows

A Comprehensive Guide:

In today’s collaborative development environment, it’s not uncommon to have multiple GitHub accounts — perhaps one for personal projects and another for work. However, managing these accounts on a single Windows machine can be tricky. This guide will walk you through the process of setting up and switching between two GitHub accounts seamlessly.

 

Prerequisites

Before we begin, ensure you have:

  • Git installed on your Windows machine
  • Two GitHub accounts
  • OpenSSH Key Agent running on your system

 

Step 1: Set Up OpenSSH Key Agent

First, we need to ensure the OpenSSH Key Agent is running:

  • Press Win + R, type services.msc, and press Enter.
  • Find “OpenSSH Authentication Agent” in the list.
  • Right-click and select “Properties”.
  • Set “Startup type” to “Automatic (Delayed Start)”.
  • Click “Start” to run the service.

 

Step 2: Generate SSH Keys

For each GitHub account, you’ll need a unique SSH key:

  1. Open Git Bash.
  2. Generate a key for your first account: ssh-keygen -t rsa -C "your-email@example.com" -f ~/.ssh/account1
  3. Repeat for your second account: ssh-keygen -t rsa -C "your-other-email@example.com" -f ~/.ssh/account2

 

Step 3: Add SSH Keys to the SSH Agent

Add your SSH keys to the SSH agent:

ssh-add ~/.ssh/account1

ssh-add ~/.ssh/account2

To verify the keys are added, run:

ssh-add -l

 

Step 4: Create SSH Config File

Create a config file in your .ssh directory:

New-Item -Path C:\Users\YourUsername\.ssh\config -ItemType File -Force

Open this file and add the following content:

#Account 1

Host github.com-account1

HostName github.com

User git

IdentityFile ~/.ssh/account1

#Account 2

Host github.com-account2

HostName github.com


User git

IdentityFile ~/.ssh/account2

 

Step 5: Add SSH Keys to GitHub Accounts

  • Get the public key content: Get-Content C:\Users\YourUsername\.ssh\account1.pub
  • Copy the output and add it to your first GitHub account in Settings > SSH and GPG keys.
  • Repeat for the second account.

 

Step 6: Test Your Configuration

Test your SSH connections:

ssh -T git@github.com-account1

ssh -T git@github.com-account2

You should see a success message for each account.

 

Using Your Accounts

When cloning a repository, use the host you specified in the SSH config:

git clone git@github.com-account1:username/repo.git

For existing repositories, update the remote URL:

git remote set-url origin git@github.com-account1:username/repo.git

 

Switching Between Accounts

When working on a project, set the local Git configuration:

git config user.name "Your Name"

git config user.email "your-email@example.com"

Always verify the remote URL before pushing:

git remote -v

 

Conclusion

By following these steps, you can efficiently manage multiple GitHub accounts on a single Windows machine. Remember to always check your Git configuration and remote URLs to ensure you’re using the correct account for each project.

This setup allows you to keep your work and personal projects separate while working from the same machine, enhancing your productivity and maintaining clear boundaries between different GitHub identities.

To view or add a comment, sign in

Others also viewed

Explore content categories