[Git] Simple code pulling, just two steps~~ —— Attached [Git download and necessary configuration tutorial]


1. Software download

Open [git official website] https://git-scm.com/ and download the version of git corresponding to the operating system.

If everything is slow to download, you can find a mirror!

The official website download is too slow, we can use the Taobao mirror to download: http://npm.taobao.org/mirrors/git-for-windows/
insert image description here
Download the corresponding version and install it!

Installation: The next step is no brainer! Installed and ready to use!

Start Git

After the installation is successful, there will be a Git item in the start menu, and there are 3 programs under the menu: you can also see the corresponding program by right-clicking on any folder!
insert image description here
Git Bash: Unix and Linux style command line, most used, most recommended

Git CMD: Windows-style command line

Git GUI: Git with graphical interface, not recommended for beginners, try to be familiar with common commands first

这里我们就以常用的Git Bash来操作演示

2. Git configuration

Set username and email address (user ID, necessary)

The first thing to do when you install Git is to set up your username and e-mail address. This is very important because every Git commit will use this information. It is permanently embedded in your commit:

git config --global user.name "DBcoding"  #名称
git config --global user.email 2696774557@qq.com   #邮箱

This setting only needs to be done once, if you pass the --global option, as Git will always use this information for everything you do on the system. If you wish to use a different name or e-mail address in a particular project, you can run this command without the --global option in that project. In short –global is a global configuration, not a specific configuration of a project.
insert image description here

View profiles at different levels:

#查看系统config
git config --system --list
  
#查看当前用户(global)配置
git config --global  --list

Second, the actual operation of Git

For daily use, just remember the following 6 commands:
insert image description here

Scenario 1. Pull the company code demo:

Because github has a wall, here we take gitee (code cloud) as an example (in fact, it is a domestic github, which is also very easy to use~)

Step 1: Open the Git interface
insert image description here
insert image description here
First, right-click Git Bash Here in an empty folder to open the git interface

Step 2: Enter the clone remote warehouse command

git clone 【公司远程仓库url】

The remote warehouse url is obtained here:
insert image description here

insert image description here
Enter
insert image description here
At this point, the default master branch of the remote warehouse will be cloned!


If you want to clone another branch, just enter this command:

git clone -b 【分支名】 --single-branch 【远程仓库url】

I'm worried that you still don't understand, let me demonstrate it again:
insert image description here
insert image description here
here I have a branch in my personal warehouse function, and the url of the remote warehouse is still the same
insert image description here

Scenario 2. Modify the local warehouse code and update the remote warehouse:

Many times, we work with multiple people in the company to complete the project. We pull the company code, write the project in the local warehouse, and then push the code of the local warehouse to the remote warehouse to update the code of the remote warehouse.

insert image description here
We arbitrarily add 'test' to the README as the file that has modified the local warehouse (the remote warehouse does not have the 'test' character at this time)
Step 1: Add the local warehouse to暂存区

git add .   //添加本地仓库所有文件至暂存区(注意:add后的点就代表所有文件,不能省略)

insert image description here

Step 2: Submit the staging area code to the database

git commit -m '注释你修改了什么'

insert image description here

Step 3: Push the database code to the remote warehouse

git push

insert image description here
Updating the remote repository is complete!
insert image description here

insert image description here
This is the modification comment written when the commit was just submitted

solve confusion

Why does it take a step-by-step process to push code from a local repository to a remote repository?
We can understand the workflow of git through the following figure:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_60297362/article/details/123024632