Using GitHub with Git

Table of contents

1. Create a personal warehouse

2. Configure SSH key

3. Clone warehouse code

4. Push code to personal warehouse

5. Code pull


1. Create a personal warehouse

1. To create a GitHub personal warehouse, first register as a GitHub user. After registration, open the user interface

Then there is the problem of configuration

After configuration, pull to the bottom and click create repository


2. Configure SSH key

1. Configure personal information

git config --global user.name "name"
git config --global user.emal "email"

 2. Generate SSH key

ssh-keygen -t rsa -C "email"

 There is no need to control the pop-up input command, just press Enter all the time

 Find the corresponding folder. Open the public key and copy the content

 

 After the addition is successful, you can try to verify it with the following command

ssh -T [email protected]

 Then you can connect normally


3. Clone warehouse code

First find a project at random, find the SSH address and copy

Open git in the target directory and enter the command (if there is no init initialization, try to initialize it first)

git clone sshAdress

 You can see that the normal download is complete


4. Push code to personal warehouse

1. After creating an empty directory, get the contents of the warehouse into the file by commanding git clone

Then open git in the current file and put the file you want to update into it. Here I added a test document.txt

2. Due to the addition of files, it needs to be submitted

git add -all
git commit --all -m "version 1"

3. Establish a remote node

git remote add origin SSH地址

 Among them, origin is a synonym for the following address, which can be changed by yourself, and the default is origin

4. Push

Enter the command in git

git push origin branch

Among them, origin is the pronoun of the address just now, and branch is the branch, which means to upload the content as a certain branch. There is only one main branch main in the current document, so use the main branch to upload

 After pushing, you can see it in the warehouse, and it has been pushed normally.


5. Code pull

In the explanation of the push code, you can see that there is a test document, the content of which is

But now the content in the warehouse has been updated, in order to keep the progress, it needs to be updated

 So do I need to clone the project again?

Of course not, it is a waste of space to do so, just use the pull code to pull, and the content of the file will be automatically updated

1. First enter the command

git fetch

 There is a return result indicating that the current file content is different from the file content in our github warehouse

At this time, you can pull the update code by entering the command

git pull

Note: The difference between the Clone command and the Pull command

The command is usually used when you first touch a project and want to download all its files git clone. This command will create a new repository locally and copy all the files in the remote repository to the local. This way you can start developing or viewing code locally.

And when you already have a copy of the old project (i.e. the local repository), you can use git pullthe command to get the latest update from the remote repository. This command will compare the differences between the local warehouse and the remote warehouse, and merge the new submissions in the remote warehouse into the local warehouse. This way you can keep your local copy in sync with the remote repository.


Guess you like

Origin blog.csdn.net/dogxixi/article/details/132295793