Two GitHub Accounts in SourceTree — Zero Headaches
April 20, 2026 • Nona Dzhurkova • 5 min read

Two GitHub Accounts in SourceTree — Zero Headaches

You have two GitHub accounts — say, one for work and one personal. Every time you switch repos, SourceTree asks for credentials, gets confused, or pulls from the wrong account. This guide fixes that permanently using SSH keys, so each repo always knows exactly who it's talking to.

1. Generate SSH Keys — One Per Account

An SSH key is like a unique digital ID card for each GitHub account. We'll create two of them — one for each account.

Open a terminal (Command Prompt or PowerShell on Windows, Terminal on Mac). Run echo %USERPROFILE% on Windows or echo ~ on Mac to find your home folder path.

First Account Key

# Windows — use your full home path
ssh-keygen -t ed25519 -C "you@firstaccount.com" -f "C:\Users\yourname\.ssh\id_ed25519_github1"

# Mac / Linux
ssh-keygen -t ed25519 -C "you@firstaccount.com" -f ~/.ssh/id_ed25519_github1

Second Account Key

# Windows
ssh-keygen -t ed25519 -C "you@secondaccount.com" -f "C:\Users\yourname\.ssh\id_ed25519_github2"

# Mac / Linux
ssh-keygen -t ed25519 -C "you@secondaccount.com" -f ~/.ssh/id_ed25519_github2

When prompted for a passphrase, press Enter twice to skip it. You'll end up with four files: two private keys and two .pub (public) files.

2. Add Each Public Key to GitHub

The public key (.pub file) is what you give to GitHub. Do this once per account.

Get the key content

# Windows — first account
type "C:\Users\yourname\.ssh\id_ed25519_github1.pub"

# Mac / Linux — first account
cat ~/.ssh/id_ed25519_github1.pub

Copy the entire output (it starts with ssh-ed25519). Then repeat for github2.

Add it to GitHub

  1. Log into your first GitHub account
  2. Go to Settings → SSH and GPG keys → New SSH key
  3. Give it a title like work-laptop
  4. Select Authentication Key as the type
  5. Paste the key and click Add SSH key
  6. If you see a Configure SSO button (common for company/org accounts), click it and authorize your organization
  7. Repeat all steps logged into your second GitHub account, using the second key

3. Create the SSH Config File

This file is the magic router. It tells your computer: "When connecting to github-account1, use key #1. When connecting to github-account2, use key #2."

Create a file called config (no extension) inside your .ssh folder:

  • Windows path: C:\Users\yourname\.ssh\config
  • Mac/Linux path: ~/.ssh/config
  • On Windows, open Notepad → save as All Files and name it exactly config (no .txt)

File contents

# First GitHub account
Host github-account1
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github1

# Second GitHub account
Host github-account2
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github2

Windows users: Replace ~/ with your full path, e.g. C:\Users\yourname\.ssh\id_ed25519_github1

4. Configure SourceTree to Use OpenSSH

SourceTree needs to use OpenSSH (not PuTTY) so it reads your config file and picks the right key automatically.

  1. Open SourceTree
  2. Go to Tools → Options → SSH Client (Windows) or Preferences → SSH Client (Mac)
  3. Set SSH Client to OpenSSH
  4. Click OK — the key field doesn't matter, the config file handles routing

PuTTY uses its own key format and ignores your ~/.ssh/config file. OpenSSH reads it, so the right key gets used automatically for each repo.

5. Test the Connection

Before touching SourceTree, verify both keys work from the terminal:

# Test first account
ssh -T git@github-account1

# Test second account
ssh -T git@github-account2

Both should reply with:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

If asked "Are you sure you want to continue connecting?" — type yes. This only happens once.

6. Update Remote URLs in SourceTree

For each existing repo in SourceTree, you need to update the remote URL to use your new SSH alias instead of github.com.

  1. Open the repo in SourceTree
  2. Go to Repository → Repository Settings → Remotes
  3. Click origin (or whatever the remote is named) to edit it
  4. Change the URL as shown below
  5. Click OK, then try Fetch

URL format to use

# Old URL (don't use this)
https://github.com/org-name/repo-name.git
git@github.com:org-name/repo-name.git

# New URL — first account repos
git@github-account1:org-name/repo-name.git

# New URL — second account repos
git@github-account2:org-name/repo-name.git

To find the right URL: go to the repo on GitHub → click the green Code button → select the SSH tab. You'll see something like git@github.com:org/repo.git — just swap github.com for github-account1 or github-account2.

7. Adding a New Repo Later

Got a new repository to work with? No new SSH keys needed — the setup you've done covers all future repos for both accounts.

If you're cloning a new repo

Instead of copying the URL from GitHub as-is, swap github.com for the right alias:

# Clone using account 1
git clone git@github-account1:org/new-repo.git

# Clone using account 2
git clone git@github-account2:org/new-repo.git

If the repo is already cloned

  1. Open the repo in SourceTree
  2. Go to Repository → Repository Settings → Remotes
  3. Edit the URL to use github-account1 or github-account2 instead of github.com
  4. Click OK and do a Fetch to confirm it works

As long as the new repo belongs to an account you've already configured, just update the remote URL. The SSH key routing is handled by your ~/.ssh/config file automatically.

You're Done

Once set up, you never touch this again. Here's what happens behind the scenes every time you push or fetch:

  • SourceTree sees git@github-account1:… in the remote URL
  • SSH config routes to the correct key file for that account automatically
  • GitHub receives the right identity and grants access to the right repos
  • You get zero prompts, zero logins, zero confusion

Featured Blogs