Running Multiple GitHub Accounts in Single Pc
2025-11-24
Introduction
Managing multiple GitHub accounts (e.g., one for work and one for personal projects) on a single machine can be challenging. By default, Git tries to use a single identity for all operations. In this guide, I'll walk you through the process of setting up SSH configs and Git Conditional Includes to seamlessly switch between your Work (Entrans) and Personal accounts.
Prerequisites
Before we start, make sure you have:
- Two GitHub accounts
- A specific folder created for your secondary projects (e.g.,
~/Per) - Git installed on your machine
Step 1: Generate Separate SSH Keys
- Open your terminal.
- Generate the key for your Work (Default) account:
ssh-keygen -t ed25519 -C "employee@workday.io" -f ~/.ssh/id_ed25519
3. Generate the key for your **Personal (Secondary)** account:
```bash
ssh-keygen -t ed25519 -C "Personal@gmail.com" -f ~/.ssh/id_ed25519_per
```
4. Start the SSH agent and add both keys:
```bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-add ~/.ssh/id_ed25519_per
```
## Step 2: Configure SSH Host Aliases
1. Open or create your SSH config file:
```bash
nano ~/.ssh/config
```
2. Add the following configuration to map the keys. Note that we map the Work account to the default `github.com`.
```text
# 1. Work Account (Default)
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519
# 2. Personal Account (Alias)
Host github-per
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_per
```
## Step 3: Configure Git Conditional Includes
1. Open your global Git configuration:
```bash
nano ~/.gitconfig
```
2. Set your global (Work) identity and add the conditional include:
```ini
[user]
name = employee-name
email = employee@workday.io
# If inside ~/Per/, load the personal config
# Note: The trailing slash is important!
[includeIf "gitdir:~/Per/"]
path = ~/.gitconfig-per
```
## Step 4: Create the Personal Git Config
1. Create the file:
```bash
nano ~/.gitconfig-per
```
2. Add your personal identity and SSH command override:
```ini
[user]
name = Personal Name
email = personal@gmail.com
[core]
# Force Git to use the personal key for commands in this folder
sshCommand = ssh -i ~/.ssh/id_ed25519_per
```
## Step 5: Connect and Clone Repositories
### For Work Repositories (Default):
Since Work is the default, clone normally using the standard URL:
```bash
git clone git@github.com:entrans/work-repo.git
```
### For Personal Repositories (Secondary):
You must use the **Host Alias** (`github-per`) and be inside the `~/Per` folder.
```bash
cd ~/Per
git clone git@github-per:personal-name/personal-project.git
```
## Step 6: Creating New Repositories
If you are starting a fresh project locally in your Personal folder instead of cloning:
```bash
cd ~/Per/new-project
git init
# Use the alias 'github-per' for the remote
git remote add origin git@github-per:personal-name/new-project.git
git push -u origin main
```
## Conclusion
You now have a robust multi-account setup\! Your Work account is the default for everything, and your Personal identity automatically activates whenever you work inside the `~/Per` directory.
```
```