Have you ever desired to manage multiple GitHub accounts on the same computer but lacked the knowledge on how to accomplish it? Fear not, for it is a simple task requiring only a small portion of code.

1. Enable OpenSSH

  1. In windows, open the “Services” app and search for OpenSSH Authentication Agent
  2. Right click over OpenSSH Authentication Agent, then Properties
  3. Set the startup type to Automatic
  4. Apply changes and click start. Then close it.

2. Create SSH Keys1

  1. Open PowerShell2
  2. Add command for the default account (personal recommended first)
1
ssh-keygen -t rsa -b 4096 -C "juanpablodiaz"
  1. Enter the path location where you want to save the key (personal_key)
1
C:\Users\juanc\.ssh\juanpablodiaz_key
  1. The key has been generated. To check, go to the folder where you save it.
  2. Add next GitHub account. (example: GitHub for work)
1
ssh-keygen -t rsa -b 4096 -C "1diazdev"
  1. Enter the path location where you want to save the key
1
C:\Users\juanc\.ssh\1diazdev_key
  1. The key has been generated. To check, go to the folder where you save it.

3. Create SSH Config File

  1. Open the file explorer in the folder where both keys are stored
  2. Create the config file
  3. Open the file in VScode and add the info below:
1
2
3
4
5
6
7
8
9
10
11
12
13
# juanpablodiaz GitHub
Host juanpablodiaz
  Hostname github.com
  User git
  IdentityFile ~/.ssh/juanpablodiaz_key
  IdentitiesOnly yes

# 1diazdev GitHub
Host 1diazdev
  Hostname github.com
  User git
  IdentityFile ~/.ssh/1diazdev_key
  IdentitiesOnly yes

4. Add Keys to GitHub

  1. Go to GitHub.com and login
  2. Go to Menu > Setting > SSH and GPG keys > new SSH keys
  3. Add the public key and save.
  4. Repet the process on the other GitHub account.

5. Add Keys to OpenSSH Cache

This is to prevent having to login to GitHub everytime I interact with GitHub.com.

  1. Open PowerShell and add the command (this will add the private key)
1
ssh-add C:\Users\juanc\.ssh\juanpablodiaz_key
  1. Repet the process for the other account (adding the private key)
1
ssh-add C:\Users\juanc\.ssh\1diazdev_key
  1. To test this add the code
1
   ssh -Tv juanpablodiaz
  1. And
1
   ssh -Tv 1diazdev

6. Preparing Folder Structure

  1. Create two folders inside a GitHub folder
  • C:\Users\juanc\Documents\Github\juanPabloDiaz

  • C:\Users\juanc\Documents\Github\1diazdev

  1. In the Users\juanc folder, Create 3 files:
  • .gitconfig
  • .gitconfig-juanpablodiaz
  • .gitconfig-1diazdev
  1. In my case, the .gitconfig file was already created.
  • Open and replace it with the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true
[includeIf "gitdir:C:Users/juanc/Documents/Github/juanPabloDiaz"]
	path = ./.gitconfig-juanpablodiaz

[includeIf "gitdir:C:\Users/juanc/Documents/Github/1diazdev"]
	path = ./.gitconfig-1diazdev
[user]
	name = Juan Diaz
	email = juanchodis@hotmail.com
[core]
	sshCommand = C:/Windows/System32/OpenSSH/ssh.exe
  1. Open the .gitconfig-juanpablodiaz and add the following code:
1
2
3
4
5
[user]
	name = juanpablodiaz
	email = juanchodis@hotmail.com
[core]
	sshCommand = ssh -i ~.ssh/juanpablodiaz_key
  1. Open the .gitconfig-1diazdev and add the following code:
1
2
3
4
5
[user]
	name = 1diazdev
	email = juan.diaz.rodriguez93@gmail.com
[core]
	sshCommand = ssh -i ~.ssh/1diazdev_key

7. Preparing Folder Structure

  1. Go to GitHub.com and find the repo
  2. Copy the last part of the SSH link.

    • SSH link: git@github.com:JuanPabloDiaz/repoName.git
    • Copy: JuanPabloDiaz/repoName.git
  1. Add the SSH link to that especific folder repo
1
git remote set-url origin juanpablodiaz:JuanPabloDiaz/repoName.git

Example:

1
2
3
git remote set-url origin juanpablodiaz:JuanPabloDiaz/doc.git
or
git remote set-url origin 1diazdev:1diazdev/JuanDiaz.git
  1. Test it by doing a git pull

Command to add a new repo from GitHub to local

1
git clone juanpablodiaz:JuanPabloDiaz/repoName.git

or

1
git clone 1diazdev:1diazdev/repoName.git

Test it by doing a git pull

Acknowledgments 📚

Resources list that I find helpful and would like to give credit to.



  1. SSH or Secure Shell is a network communication protocol that enables two computers to communicate.
    Go to GitHub Doc 

  2. PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell and the associated scripting language.
    To undestand better any line of code in PowerShell visit (Explain Shell