Git remote warehouse use

1. Introduction

This tutorial mainly introduces how to use Github to create a warehouse, and realize the connection management of multiple computers to the warehouse.

Click here for the Git download address. You can just click and confirm the installation if you don't want to toss.

Second, the process

1. Connect to GitHub with SSH Key

  • Create SSH Key locally

Check whether there is a ".ssh" directory in the user's home directory. If there is, it means that there is an SSH Key. You can skip this step directly.

Open Git bash on the local desktop and enter the following statement to generate an SSH Key,

$ ssh-keygen -t rsa -C "引号内替换为你的的邮箱地址"

After you press Enter and execute, you can see the SSH Key in the .SSH folder, where  id_rsa is the private key  id_rsa.pub is the public key, the main thing that the tutorial will use is the public key, so you can tell anyone with confidence

  • Log in to GitHub to establish a trust relationship

Log in to your GitHub account ( click here if you don’t have a GitHub account ), and click on your avatar in the upper right corner to enter the settings

Click New SSH Key to add SSH Key.

Associate the id_rsa.pub public key with the account. The main function here is that Github needs to use the public key to confirm whether the warehouse submission is yours. Make sure that only you can make changes to the warehouse. If you have multiple computers, just need By binding the public key of the computer every day, it can be pushed on multiple computers.

At this point, the local has established a trust relationship with the GitHub account, and then you can create a remote warehouse and synchronize with the local

2. Create a local warehouse

  • Initialize the local warehouse

Open Git Bash in the local project folder, enter the following statement to initialize the warehouse, after the initialization is completed, a .git folder will be generated for version control, and the master branch will be automatically generated.

$ git init

Enter the following statement to add all files to the temporary storage area

$ git add .

Enter the following statement to submit the files in the temporary storage area to the current branch (master branch), so that the local branch will include all the files in the folder into the file library, and then the local version library will be temporarily put on hold, and the remote version will be created on GitHub. Library.

$ git commit -m '此处是此次提交说明,随便写'

3. Create a remote repository

  • The first place: Enter the GitHub interface, click the plus sign in the upper right corner, and click new repository to pop up the repository creation interface.
  • Part 2: Warehouse name, fill in by yourself.
  • The third place: used to select the warehouse type. If you choose public, it is a public warehouse. Everyone can view the code in this library. If you choose private, it is a private warehouse. Only you can view the code in the library (github private warehouse after 2019 Free), how to choose depends on personal preference,
  • Fourth place: After filling in the first two places, click here to generate a remote warehouse

After the generation is completed, you can enter the warehouse to get the push address of the current warehouse, copy this address, and use it to establish contact with the local warehouse in the next step

4. Establish a connection between the remote warehouse and the local

Run the following statement in the local warehouse, the address after origin is the address of the remote warehouse copied in the previous step, and then you can push the files in the local warehouse to the remote warehouse

$ git remote add origin [email protected]:oneKonw/CesiumTest.git

Enter the following statement to push the local warehouse to the remote warehouse. After adding, the name of the remote warehouse will be called oringin. The -u here will associate the master of the local warehouse with the remote master branch. You can push -u to it later. , You can push the content of other branches as long as you change the name of the master to the branch name. In addition, GitHub limits the size of the pushed file to 100m, so large data should not be included in the repository.

$ git push -u origin master
// 建立联系以后推送可以把 —u 去了

After completing the above process, you can see the local files that have been pushed in the GitHub warehouse interface, and then continue to push the files and continue to use the git push statement.

5. Multi-computer collaboration

In many cases, development needs to be coordinated on multiple computers. Next, I will introduce how to synchronize code on multiple computers.

  • Add the SSH Key of another computer under development to GitHub, refer to the first step

  • Clone the remote warehouse to the local

Copy the warehouse address as shown in the figure

Open Git Bash in the local folder, enter the following statement, you can clone the remote warehouse to the local

$ git clone [email protected]:oneKonw/CesiumTest.git
  • Synchronization Update

Submit the code on one computer, and want to synchronize the remote code on another computer, execute the following statement, master is the branch name, it depends on the specific situation

$ git pull origin master

 

Guess you like

Origin blog.csdn.net/oneKnow/article/details/106873811