1. Introduction to the basic use of Git

1. What is Git?

Git is a free and open source distributed version control system. It is essentially a software. When using it, users need to input various commands (of course, there is also a graphical interface version) to complete the desired version management operations.

The initial version of Git was developed by Linus Torvalds, the creator of Linux, using C language. It was mainly used for version management of Linux kernel source code, and now it has developed into the most mainstream distributed version control system.

Git official site:

https://git-scm.com/

2. Git download and install

Git has windows, linux and other systems to install and use, because I mainly learn to use git under windows, here only record the installation and use under windows.

First you need to download the git for windows software. You can go to the above official website to download, or you can also go to this website to download:

https://gitforwindows.org/

After downloading, you will have a program named like this: Git-2.38.1-64-bit.exe

During the installation process, follow the default configuration all the way to next. After the installation is complete, you can click the right mouse button anywhere to see:

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-SOw1lGOT-1668347818607)(../picture/image-20221112150804078.png)]

The above two menus, one has a UI interface, and the other is in the form of a command line. The command line is similar to the command under Linux.

We mainly use the Git Bash Here command line form, click to open this software as follows:

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-YOQlFEAg-1668347818607)(../picture/image-20221112151002851.png)]

3. Set Git username and email address

When using Git for the first time, you must first set up your username and email address. This information will be used when using git to submit changes later, and will be written into the information of each submission.

The setting command is as follows:

git config --global user.name "luobeihai"
git config --global user.email 571688853@qq.com

If you don't set the username and email information, we can't use the git commit command to submit.

4. Git basic workflow

The figure below shows the basic workflow of Git. This picture contains about 7 commands. In our daily use of git, we basically use these 7 commands the most.

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-84Ivbp8i-1668347818608)(../picture/image-20221113211045168.png)]

1. Use git clonethe command to clone the Git resource from the remote warehouse as the local warehouse;

2. Checkout the code from the local warehouse to the workspace, and then modify the code;

3. Add the code modified in the workspace to the temporary storage area;

4. Submit the contents of the temporary storage area to the local warehouse; the local warehouse saves the modified historical versions;

5. If you need to share the code with the team, you can push the modified code to the remote warehouse.

5. Several important concepts related to Git

1. Workspace: It is a directory that we can see on the computer. In fact, it is the upper level directory of the directory where the .git folder is located, and this entire directory is the workspace.

2. Temporary storage area: English is called stage or index. It is generally stored in the index file (.git/index) under the .git directory, so we sometimes call the temporary storage area the index (index). It is actually just a file that holds information about the list of files to be submitted.

3. Repository (local warehouse): In fact, it is the .git directory, which is a hidden folder in the workspace.

4. Remote warehouse: It can be understood as a remote server, which can store our project files remotely.

The following picture can vividly show the relationship between the workspace, version library, and temporary storage area.

insert image description here

6. Git common commands

Order effect other instructions
git init Initialize a git repository in the current directory
git clone Download the remote's entire codebase, including its history
git add + file path Add the modified files in the workspace to the temporary storage area . Indicates adding all modified files in the current directory to the temporary storage area
git commit Submit the files in the temporary storage area to the local warehouse
git push Push to remote warehouse
git status View the status of the local warehouse file and display the changed file
git log Show the version history of the current branch
git diff Show the difference between the staging area and the working area
difference
git remote -v Show all remote repositories

Guess you like

Origin blog.csdn.net/luobeihai/article/details/127838320