Skip to content

This repository provides a step-by-step guide on how to set up and manage multiple GitHub accounts on a single laptop using SSH authentication. It is designed to help developers, students, and professionals who need to work with multiple GitHub accounts seamlessly.

Notifications You must be signed in to change notification settings

TVATDCI/git-remote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

GIT-REMOTE (extended version)

# Setting Up Multiple GitHub Accounts on One Laptop

This repository provides a step-by-step guide on how to set up and manage multiple GitHub accounts on a single laptop using SSH authentication. It is designed to help developers, students, and professionals who need to work with multiple GitHub accounts seamlessly.

1️⃣ Adding a Second GitHub Account to This Laptop

Step 1: Generate a New SSH Key for the Second GitHub Account

ssh-keygen -t rsa -b 4096 -C "[email protected]"
  • Save it as ~/.ssh/id_rsa_second
  • When prompted, enter a passphrase (or leave empty for no passphrase).

Step 2: Add the New SSH Key to the SSH Agent

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_second

Step 3: Add the SSH Key to GitHub

  • Copy the public key:
cat ~/.ssh/id_rsa_second.pub
  • Go to GitHub → Settings → SSH and GPG keys → New SSH Key
  • Paste the copied key and save.

Step 4: Configure SSH for Multiple GitHub Accounts

Edit (or create) the SSH config file:

nano ~/.ssh/config

Add the following lines:

# First GitHub Account
Host github.com-first
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_first

# Second GitHub Account
Host github.com-second
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_second

Save and exit (Ctrl + X, then Y, then Enter).

Step 5: Test the SSH Connection

✅ Expected output:

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

2️⃣ Cloning a Repository from the Second GitHub Account

git clone [email protected]:YourSecondUsername/YourRepo.git
  • Replace YourSecondUsername and YourRepo with your actual GitHub username and repo name.

Verify Remote URL

cd YourRepo
git remote -v

✅ Expected output:

origin  [email protected]:YourSecondUsername/YourRepo.git (fetch)
origin  [email protected]:YourSecondUsername/YourRepo.git (push)

3️⃣ Setting Local Git Config for the Second Account

Since the global config still points to the first account, we need to configure Git locally for this specific repo.

git config user.name "YourSecondUsername"
git config user.email "[email protected]"

Verify Local Git Config

git config --list --local

✅ Expected output:

user.name=YourSecondUsername
[email protected]

4️⃣ Testing the Setup with a Commit

echo "Testing new setup for second GitHub account" >> test-second.txt
git add test-second.txt
git commit -m "Test commit for second GitHub account"
git push origin main

✅ If successful, you should see the commit appear on GitHub!


🎯 Final Notes

  • Now, you can seamlessly switch between accounts by navigating to the appropriate repo.
  • All future commits in the second account's repo will use the second GitHub account.
  • To switch accounts, just navigate between different repositories configured for each account.

Additional note!

If you cloned a repository from your second GitHub account but want to push it to your first GitHub account, you need to change the remote URL from the second account to the first account. Here’s how you do it:

1️⃣ Verify the Current Remote URL

Run this in the cloned repo:

git remote -v

✅ Output should look like:

origin [email protected]:SecondAccountUserName/git-remote.git (fetch)
origin [email protected]:SecondAccountUserName/git-remote.git (push)

This confirms that the remote is linked to your second GitHub account.

2️⃣ Remove the Current Remote

Since you want to push this repo to your first account, you need to remove the existing remote:

git remote remove origin

3️⃣ Create a New Repository in Your First Account

  • Go to GitHub → Your First Account.
  • Click New Repository.
  • Give it a name (e.g., git-remote-first).
  • Do NOT initialize with README, .gitignore, or a license (since you already have a repo locally).
  • Copy the SSH URL (it should look like this):
[email protected]:FirstAccountUsername/git-remote-first.git

4️⃣ Add the New Remote for Your First Account

Now, link your local repo to your first GitHub account:

git remote add origin [email protected]:FirstAccountUsername/git-remote-first.git

Verify it:

git remote -v

✅ Expected output:

origin [email protected]:FirstAccountUsername/git-remote-first.git (fetch)
origin [email protected]:FirstAccountUsername/git-remote-first.git (push)

5️⃣ Push the Repository to the First Account

git push -u origin main

✅ If successful, your repository is now in your first GitHub account!


🎯 Summary

✔️ Clone the repo from the second account ✔️ Remove the existing remote (git remote remove origin) ✔️ Create a new repo on the first account ✔️ Add the new remote from the first account ✔️ Push your local repo to the first account

About

This repository provides a step-by-step guide on how to set up and manage multiple GitHub accounts on a single laptop using SSH authentication. It is designed to help developers, students, and professionals who need to work with multiple GitHub accounts seamlessly.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published