github gitlab multi-user multi-platform switching

1. Background

I need to use account 1 to log in and manage github accounts

I need to use account 2 to log in and manage gitlab accounts

2. Set up account mailbox

Set account 1 username and email

git config --global user.name "miaojiang"
git config --global user.email "[email protected]"

3. Generate a local key

Generate the key corresponding to account 1

ssh-keygen -t rsa -C '[email protected]'

Enter three times in a row

4. Add public key to github

4.1. Check the key

Path: Usually located in the user's ~/.ssh/directory

cd ~/.ssh

view key

  • id_rsa Is the private key file used to decrypt encrypted data.
  • id_rsa.pub is the public key file used to share your public key with others so they can send encrypted data to you.

4.2, github add public key

1. Fill in the public key content in the setting of github

read and copyid_rsa.pub 里面的内容

cat id_rsa.pub

2. Log in to github--click on the avatar--Setttings

3、SSH and GPC keys

 Click New SSH Key to add the public key

 

5. Local project push

5.1 github create warehouse

For example, create a warehouse named mock

5.2 Local setup warehouse

1. Enter the project path and execute

git init

2. Add project files

git add README.md

or

git add .

3、commit

git commit -m "first commit"

4、
git branch -M master

5. Associate remote warehouse

git remote add origin [email protected]:187133/mock.git

Notice:

 Generate remote warehouse address, you can choose HTTPS mode and SSH mode

If you choose the HTTPS method, you need to fill in the user name and password when submitting the code later.

For convenience, I choose the SSH method to generate a remote warehouse link.

 

6. Push

git push -u origin master

6. Switch user name and switch platform

6.1, local backup github key

1. Access path:

cd ~/.ssh

2. Backup

mv id_rsa id_rsa_github
mv id_rsa.pub id_rsa.pub_github 

6.2 Set up a new username and a new mailbox

 git config --global user.name "zhangsan"
git config --global user.email "[email protected]"

6.3 Generate a new key

ssh-keygen -t rsa -C '[email protected]'

Enter three times in a row

6.4 A new warehouse can be associated

git remote add origin [email protected]:zhangsan/mock.git

7. Associate the new warehouse

The local warehouse has been associated with the remote A warehouse before, and now I want to unlink the local project from the A warehouse and associate it with the new B warehouse.

1. Delete the remote library of the associated origin

git remote rm origin

2. Associate the new warehouse

git remote add origin https://gitee.com/xxxxxx.git

8. Error handling error: remote origin already exists.

 

If you clone someone else's warehouse and complete your code on this basis, you may encounter the following problems when pushing to your own warehouse: error
: remote origin already exists. It means that the remote warehouse already exists.
So you have to do the following:
1. First enter git remote rm origin to delete the remote library associated with origin
2. Associate your own warehouse git remote add origin https://gitee.com/xxxxxx.git
3. Finally git push origin master , so that it is pushed to your own warehouse
 

Guess you like

Origin blog.csdn.net/qq_39208536/article/details/131919488