0%

One PC, two git accounts

🐱 Generate the corresponding ssh key. Add the generated id_rsa.pub to the git SSH key

1
2
ssh-keygen -t rsa -C "x1@email.com"
ssh-keygen -t rsa -C "x2@email.com"

Pressing Enter directly will generate /c/Users/you/.ssh/id_rsa

1
2
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]

Pay attention to renaming to avoid files being overwritten. We need to enter the name manually

1
2
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): /c/Users/you/.ssh/id_rsa_x1

🐶 Write the following to the config file in the ~/.ssh/config directory. If this file does not exist, create one manually.

1
2
3
4
5
6
7
8
9
10
11
# default
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_x1

# two
Host x2.github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_x2

🐭 Test if it can communicate normally

1
2
ssh -T git@github.com
ssh -T x2.github.com

Use ssh to clone the repository

1
git clone git@github.com:x2/xxx.git

Set each repo username/mailbox separately

1
2
git config user.name x2
git config user.email "x2@email.com"