Those git command pits in project practice---it is recommended that git Xiaoxin practice/understand this article is enough

git study guide (beginner)

  Hello uu, you are so happy that the chestnuts that exploded have come back to life. The first month of staying in the new company went smoothly but nervous, delicious and exciting.
insert image description here
  Why dishes? Because I don't know how to use git,
insert image description here
  what are the consequences of not using git? The leader asked me to look at the code, but I don't know where to look. Doesn't that make me look low all of a sudden?
  No! can not do this. I must learn this git, and I can't let others think that we are good at the beginning. If you don't know this tool yet, then read on. I share all the git knowledge I have learned with you~
insert image description here

What are git and github

  First of all, since git is used in work, we need to know what git is, what it does, and why we use it. What benefit can it bring us.

  git: in short ------ code management tool

  • is an open source distributed version control system
  • Can effectively and quickly handle project version management from very small to very large
  • Better management of program code: such as submitting modified code and viewing the original code

  github: in a nutshell - code hosting

  • GitLab is a web-based Git repository management tool developed by GitLab Inc. using the MIT license
  • And it has wiki and issue tracking functions.
  • Use Git as a code management tool, and build a web service on this basis.

Why learn git (git is really important)

  Next, we explain why it is important to use git from two aspects:

  • Workflow after work
      I am a front-end developer: My daily work flow is like this:
      turn on the computer, start the Mac operating system —> open vscode and mac terminals —> enter the command npm run serve through the command line to start my Local debugging environment ----> develop the content of the day ------> through the command line git commit; git push to submit my day's work code ------> end the work.
      At work, we have to use git to commit our code. This is an essential skill. If you do not know the most basic operations. You may be considered bad by your peers (Once they form a bad impression of you, it is difficult to change)
  • The benefits of synchronous development of git
      I have completed my first business requirement in the new company in the past two days, and the business requirement is over. I want to show my content to my leader, to test, to other developers, how do I see it? Invite them to your seat to watch? It is necessary to submit online code to share with them. But:
      we must understand that software development must be developed by a team, so there is a division of labor between members, then this will happen, member A has performed data addition logic operations on the project At the same time, member B is also performing data deletion logic operations on the project. The blueprint of the project before the operation is definitely the same, but suppose A completes the operation and uploads to the server first, and then B also completes the operation and uploads to the server. May I ask what will happen? Obviously, the file uploaded by B will overwrite the file of A, then the logic written by A will be invalid, so is it true that all the work done by A is useless... Pulling the online code is also the same logic.
      So it is really, really necessary to use code version management tools correctly.

How git works

1. The working principle of git is roughly shown in the following figure:

insert image description here

2. git is mainly divided into the following parts

insert image description here

  • Workspace (workspace): After the current folder is initialized by the git init command (or by cloning), a hidden folder of .git will be generated, then the space where these files we can directly modify is the workspace
  • Temporary storage area (stage/index): when we use the git add [file name] or git add . Storage area (the contents of the temporary storage area become the same as the work area)
  • Local warehouse (repository): After we operate the code in the workspace, we submit it to the local warehouse
  • Remote warehouse (remote): The warehouse we submit to the network is the remote warehouse
  • Branch: Git can create a side branch for each programmer, and developers develop and submit on their own branches. After the project development is completed, programmers will merge their own branches into the main branch to realize the work of collaborative development

git operation steps and common commands

Graphic:
insert image description here
process diagram

1. The first thing about git operation after entering the company

// 1)先创建⼀个项⽬所在的⽂件夹
mkdir <文件夹名字>

//2) git仓库初始化命令
git init

//3)查看当前git的状态
git status

//4)拉取线上的代码===我们进入公司肯定是已经有了项目文件了,所以要从线上拉取项目代码
git clone (https的代码地址/ssh的代码地址)

//5)添加项目组
//找项目的管理人员将自己的账号添加到项目组才有权限开发代码,对代码进行推送和拉取

//6)创建分支===》在本地分支上创建新的开发分支完成开发,完成开发后上传到远程分支
	//6.1)检查自己所属分支
		git branch 查看本地所属分支
		git branch -a 查看所有的分支
	//6.2)在master分支上面创建relase分支
		git checkout -b release:创建并切换到release分支上
		git checkout “分支名”   切换到目标分支
	//6.3)在relese分支上创建dev分支和pre分支
		git checkout -b dev   创建并切换到dev分支
		git checkout -b pre	创建并切换到pre分支
	//6.4)假设开发功能页面,需要在dev分支上面创建开发分支
		git checkout -b  <分支名称(尽量与本地分支名一致)>

2. After the function development is completed, submit the code to the dev branch

//git pull --rebase origin dev(选用)----用来将线上的dev分支最新代码合并到本地分支代码(在你开发的过程中,线上dev分支如果有人提交了代码,那么,你是不是就得同步dev的分支到自己的分支,以保持代码的最新状态)
//1)上传代码到自己的分支
// 推送代码到暂存区:  git add .  
//从暂存区将代码存到本地仓库
	//第一次提交使用:git commit -m "提交分支的描述"
	//第n次提交:   git commit --amend ===》使用	***:wq***   退出
	//git commit -m尽量只使用一次,追加内容或后面提交尽量用it commit --amend追加
//推送至自己的线上分支  git push -f origin  <自己的分支名>

//2)提交合并申请====>在网页上提交合并请求到dev分支(询问组长测试分支的名称)---》交由组长审核

//3)在网页上提交合并请求到pre分支(询问组长pre分支的名称)---》交由组长审核

  The above are the git commands and processes we commonly use in our work~
  I hope it will be helpful to your work~~

Commonly used git tools

   vscode自带代码提交功能
   Sourcetree

  These two tools are commonly used submission tools for git code, and they can be installed and used directly. Interested students can learn more and use it.
  Even if there is a faster upload method, it is recommended that you use the habit of commands, which will not cause too serious merge problems or code conflicts.
  I hope the above sharing can help you~
insert image description here

Guess you like

Origin blog.csdn.net/m0_62209297/article/details/125226558