Coding Dimension Logo
CodingDimension
DevOps

Push One Local Repo to Two GitHub Accounts (Remotes + SSH)

Published
Aug 14, 2026
Reading Time
10 min read

Admin

Author

Keep one local Git folder and update two GitHub accounts with a second remote. Covers empty Repo B setup, Windows SSH Host aliases, username typos, and Repository not found.

Overview

One local Git project can update two GitHub accounts at once. You keep a single working folder and add a second remote — no re-clone, no copy-paste of files.

This guide assumes Repo A is already live on GitHub and you want the same history on Repo B under a second account. It covers HTTPS remotes first, then the Windows SSH multi-account setup that usually bites people next.

                    ┌── GitHub Account 1 (origin)
Local Project ──────┤
                    └── GitHub Account 2 (second)

What you need

  • An existing local Git repo that already pushes to Account 1
  • A second GitHub account with permission to create repositories
  • On Windows: Git for Windows + OpenSSH (built into modern Windows)
  • Optional but recommended for 2 accounts: a separate SSH key per GitHub account

1. Stay in your existing project

Do not delete or re-clone. Open the folder that already works:

cd "D:\path\to\your\project"
git status

You want something like:

On branch main
Your branch is up to date with 'origin/main'

If Git says you are not on a branch or the folder is not a repo, fix that first — this guide starts from a healthy local repo.

Confirm your current branch name:

git branch --show-current

If you still use master, either push master below or rename once:

git branch -M main

2. Leave the first remote alone

git remote -v

Typical output:

origin  https://github.com/OLD-ACCOUNT/my-project.git (fetch)
origin  https://github.com/OLD-ACCOUNT/my-project.git (push)

Or with SSH:

origin  git@github.com:OLD-ACCOUNT/my-project.git (fetch)
origin  git@github.com:OLD-ACCOUNT/my-project.git (push)

Do not change origin. That remote is your already-working Account 1 connection.

3. Create an empty repo on Account 2

  1. Log into the second GitHub account
  2. Click New repository
  3. Name it (example: my-project)
  4. Keep it empty: no README, no .gitignore, no license
  5. Create the repository

Copy the URL GitHub shows. HTTPS example:

https://github.com/SECOND-ACCOUNT/my-project.git

SSH example (we will refine this for multi-account SSH later):

git@github.com:SECOND-ACCOUNT/my-project.git

Use the exact owner username from the Code → SSH / HTTPS button. Typos in the username are the #1 cause of Repository not found after SSH auth succeeds.

4. Add a second remote

git remote add second https://github.com/SECOND-ACCOUNT/my-project.git

Verify:

git remote -v
origin   https://github.com/OLD-ACCOUNT/my-project.git
second   https://github.com/SECOND-ACCOUNT/my-project.git

You can name the remote anything (backup, work, personal). This guide uses second.

5. Push to Account 2

git push -u second main

If your branch is still master:

git push -u second master

Daily workflow after that:

git push origin main    # Account 1
git push second main    # Account 2

6. HTTPS authentication tip

GitHub no longer accepts account passwords for Git over HTTPS. Use a Personal Access Token (PAT) when prompted for a password.

If Windows Credential Manager already saved Account 1, Account 2 HTTPS pushes can silently use the wrong credentials. For two accounts long-term, prefer SSH with Host aliases (next sections).

7. Why two GitHub accounts need SSH aliases

GitHub sees every SSH connection as git@github.com. If both accounts use the default key, GitHub always authenticates as whichever key is offered first — usually Account 1. Account 2 then looks “broken” even though the remote URL looks fine.

Fix: give each account its own key and a custom Host alias in ~/.ssh/config.

Create a second key (if you do not have one)

ssh-keygen -t ed25519 -C "second-account@email.com" -f %USERPROFILE%\.ssh\id_ed25519_second

Add the .pub file to GitHub → Account 2 → Settings → SSH and GPG keys.

Windows SSH config

Edit (create if missing):

notepad %USERPROFILE%\.ssh\config

Example with two accounts:

Host github.com
    HostName github.com
    User git
    IdentityFile C:/Users/YOUR_WINDOWS_USER/.ssh/id_ed25519
    IdentitiesOnly yes

Host github-second
    HostName github.com
    User git
    IdentityFile C:/Users/YOUR_WINDOWS_USER/.ssh/id_ed25519_second
    IdentitiesOnly yes

IdentitiesOnly yes forces that Host to use only the listed key — critical when multiple keys exist.

The Host name on the left (github-second) is an alias. Your Git remote must use that exact alias, not a name you invent later.

8. Point second at the SSH alias

git remote set-url second git@github-second:SECOND-ACCOUNT/my-project.git

Test the alias (not plain github.com):

ssh -T git@github-second

Success looks like:

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

Then push:

git push -u second main

Common mistakes (and exact fixes)

A. ssh: Could not resolve hostname github-wisdora

You used an SSH alias in the remote URL that does not exist in ~/.ssh/config.

Check what aliases you actually have:

type %USERPROFILE%\.ssh\config

If your config says:

Host My_id_second
    HostName github.com
    User git
    IdentityFile C:/Users/YOUR_WINDOWS_USER/.ssh/My_id_second_github
    IdentitiesOnly yes

then the remote must use My_id_second, not github-second or github-wisdora:

git remote set-url second git@My_id_second:SECOND-ACCOUNT/my-project.git
ssh -T git@My_id_second

B. SSH says Hi username… but push says Repository not found

Authentication worked. The repo path is wrong or you lack access.

Classic typo pattern:

  • SSH authenticated as shivamagrawals
  • Remote pointed at shivamagarwals/... (extra a)

GitHub returns ERROR: Repository not found for both missing repos and private repos you cannot see — so double-check the owner spelling.

Fix:

  1. Open the second-account repo in the browser
  2. Click Code → SSH and copy the exact URL
  3. Replace only the host with your alias

If Code → SSH shows:

git@github.com:correct-username/my-project.git

set:

git remote set-url second git@My_id_second:correct-username/my-project.git
git remote -v
git push -u second main

C. Wrong account authenticated

ssh -T git@github-second greets Account 1 instead of Account 2. Usually missing IdentitiesOnly yes, or the wrong IdentityFile path. Fix the config block, then retest with ssh -T before pushing.

D. Second remote already exists

error: remote second already exists.

Update the URL instead of adding again:

git remote set-url second git@My_id_second:SECOND-ACCOUNT/my-project.git

Optional: push both remotes in one command

You can add a second push URL on origin:

git remote set-url --add --push origin https://github.com/OLD-ACCOUNT/my-project.git
git remote set-url --add --push origin https://github.com/SECOND-ACCOUNT/my-project.git
git push origin main

That updates both destinations when you push origin. Many people still prefer two named remotes (origin + second) so each push target stays explicit and easier to debug.

Cheat sheet

# Inspect
git status
git branch --show-current
git remote -v
type %USERPROFILE%\.ssh\config
ssh -T git@YOUR_SSH_ALIAS

# Add / fix second remote
git remote add second https://github.com/SECOND-ACCOUNT/my-project.git
git remote set-url second git@YOUR_SSH_ALIAS:SECOND-ACCOUNT/my-project.git

# Push
git push origin main
git push -u second main

Final mental model

  • One local folder — one Git history
  • Two remotes — two GitHub homes
  • Two SSH Host aliases — two GitHub identities on one PC
  • If ssh -T greets the right user, auth is done; remaining errors are almost always the owner/repo path

Paste git remote -v and the greeting from ssh -T git@YOUR_ALIAS whenever something fails — those two lines usually pinpoint the next fix.

#git#github#ssh#windows#devops
Share:

Comments

0

Login to post a comment.

Sign in

Loading comments…