How to use Git to host projects to both GitHub and Gitee repositories

Preface

  Recently, I plan to host the code of the previous project on GitHub. Considering future factors, I also established a warehouse on Gitee. This article introduces how to use Git to host projects to both GitHub and Gitee repositories.

  Of course, the premise is that you have installed Git and registered GitHub and Gitee accounts.

1. Create a GitHub repository

  Warehouse name testone, add a project description, check it Public, then add a READMEfile, and finally click Create repositoryCreate Warehouse. As shown below:

Insert picture description here

2. Build a Gitee warehouse

  Click Code, copy the address link of the GitHub warehouse first, then go to Gitee to create the warehouse, drop down the page, click 导入已有仓库, copy the address link of the GitHub warehouse, and click 创建.

Insert picture description here
Insert picture description here
Insert picture description here

  The protocol type can be unselected

Insert picture description here

3. Clone the GitHub repository to the local

  Right-click to open the local folder Git Bash, and then clone the GitHub repository you just created to the local. The clone command is as follows:

	git clone https://github.com/xiayouran/testone.git

Insert picture description here
  After cloning, there will be a folder in the current directory, the name of the folder is the warehouse name, and then enter this folder:

	cd testone

Insert picture description here
  Then create a file in the current folder test.txt, write some content and save it.

Insert picture description here

4. Push the updated project

  Check the status first, the font is red:

	git status

Insert picture description here
  Then use the following command to add all the files in this folder to the temporary storage area

	git add .

  Check the status again. At this time, the font is green, indicating that it has been added to the local project:

Insert picture description here

  Then add the submission description through the following command, without this submission:

	git commit -m 'submit a txt file'

Insert picture description here

  Then use the following command to add the Gitee warehouse address to the existing remote locally:

	git remote set-url --add origin https://gitee.com/xiayouran/testone.git

  Then push through the following command:

	git push

Insert picture description here
  Refresh the respective warehouse, you can see that the test.txtfile has been pushed to the warehouse:

Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_42730750/article/details/109226367