Every programmer can have multiple GitHub accounts, after all, GitHub has many benefits and functions, but! But! But! Usually, the first time I play Github, I will do this, SSH to github, bind the unique public key, so that later when I am skilled or github increase, the question is, how can a computer manage multiple Github accounts at the same time?
This article will talk about how to use multiple GitHub accounts on the same computer.
How to use multiple GitHub accounts on one computer
Online after all, much similar copywriting, but much the same, anyway, I tried to refer to a few articles are failed, some articles are directly complex *, wrong can be wrong a piece; The method introduced in this paper is effective, but the steps are recommended to pay attention to;
Step 1 Delete the global Github account
This step method after all, this step will not be introduced
Step 2 Generate the corresponding account key
- Go to the SSH folder (usually: C:\Users\user.ssh) to generate a new public key and name it as
id_rsa_2
(Make sure the name of the key file is different from the previous one)- Then generate a new public key to ensure that each account has a different name
Run the following command to generate the key: ssh-keygen -t rsa -f ~/. SSH /id_rsa_2 -c “[email protected]”
Id_rsa_2: key name; [email protected]: corresponding email address of the account;
Step 3 Github binds SSH
This step online more tutorial, basic can, so omitted; If necessary, you can search online for keywords: How do I use SSH key to link to Github
Step 4 Configure the account key management file
Create a config file in the.ssh folder and edit it.
# default // The default git account
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# two // Second accountCreate a github alias Host two.github.com ## Host user1 ##/.ssh/iD_rsa_2 ## Git account corresponds to key # three// The third account
Host three.github.com
HostName github.com
User user2
IdentityFile ~/.ssh/id_rsa_3
Copy the code
Testing SSH links
ssh -T [email protected]
ssh -T [email protected]
# Hi two! You've successfully authenticated, but GitHub does not provide shell accessCopy the code
Basically, we have the binding number, so let’s try it out
Step 5 clone the project
Clone the project to a local location, such as a regular SSH address, but the git file was configured in the previous step, so we used an alias when cloning the file.
- Error :(directly download from SSH address)
git clone [email protected]:sevenliao/sliao-cli.git
- Correct :(download directly from SSH address)
git clone [email protected]:sevenliao/sliao-cli.git
Step 6 Bind the git account corresponding to the project
This step is different from binding the order global Git account, which is project-specific;
Run the following command
git config user.name username
git config user.email useremail
Copy the code
Then you can manage your git account code normally