Cheng Yu

Time:2020-12-2

Create code repository

Use gitee as an example (GitHub is similar to gitee)

1. Click + in the upper right corner of gitee and select new warehouse

2. Select to fill in warehouse information and create it

3. The server is ready. Start to prepare locally

(1) Git global settings

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

(2) Create local git repository

#Create folder
mkdir test
#Enter folder
cd test
#Initialization
git init
#Creating files
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/Tong_Cheng_Yu/test.git
git push -u origin master

(3) Existing warehouse

cd existing_test
git remote add origin https://gitee.com/Tong_Cheng_Yu/test.git
git push -u origin master

The local library is associated with both GitHub and gitee

After the above steps, you can create a remote repository in GitHub and gitee. Some friends can want to maintain their own code to gitee and GitHub. Two warehouses can be associated locally. You can choose to submit to different warehouses. The next steps are to set up a local association of two warehouses.

(1) View the local association (you can see that the local library is already associatedoriginAnd the remote library points to gitee)

git remote -v

origin	https://gitee.com/Tong_Cheng_Yu/test.git (fetch)
origin	https://gitee.com/Tong_Cheng_Yu/test.git (push)

(2) We can delete the existing gitee remote library, first associate GitHub remote library, and then associate gitee remote library

#Delete local association
git remote rm origin
#Associate GitHub
git remote add github https://github.com/t-c-y/test.git
#Associated gitee
git remote add gitee https://gitee.com/Tong_Cheng_Yu/test.git

(3) We use itgit remote -vViewing the remote library information, you can see two remote libraries

gitee	https://gitee.com/Tong_Cheng_Yu/test.git (fetch)
gitee	https://gitee.com/Tong_Cheng_Yu/test.git (push)
github	https://github.com/t-c-y/test.git (fetch)
github	https://github.com/t-c-y/test.git (push)

(4) Push code

If you want to push to GitHub, use the command

git push github master

If you want to push to gitee, use the command

git push gitee master

Local and remote association graph (so that the local library can synchronize with multiple remote libraries at the same time)

How far library submit pull code in idea

1. Pull code (click pull to select different remote warehouses)

​    

2. Submit code (first submit to the local warehouse, then push to the remote warehouse, and then push to the remote warehouse, which is also optional)

​     

I hope this article can help you.