A very classic picture:
When multiple people work together, there is generally a master branch, which is used to merge the code of the small partners into the dev branch. Each small partner created based on the dev branch has its own branch, such as myBranch.
- The master branch is the main branch, so it must be synchronized with the remote at all times;
- The dev branch is the development branch, and all team members need to work on it, so it also needs to be synchronized with the remote;
- Whether the myBranch branch is pushed to the remote depends on whether you cooperate with your small partners to develop on it.
development commit
When you just entered the project team and need to develop based on the dev branch, you need to: (1) clone the code (2) create your own branch based on the dev branch (3) develop based on your own branch, and then submit it to the remote branch superior
git clone ...
git checkout dev
git checkout -b myBranch//创建并切换到自己分支
--
进行开发ing...要提交代码了
git add .
gst
gc -m'首页ok'
gst
git push origin myBranch(缩写gp)
Merge code
Before developing every day, git pull the dev branch to ensure that editing is based on the latest dev branch.
However, if the small partner is developing and finds a new commit on the dev branch, it shows that his local dev branch version has fallen behind.
Solution: Based on myBranch, merge workspace changes with dev changes. For specific methods, see the following two
method one
First put the code changes in your own workspace into the local warehouse, then pull the latest code of the remote dev to the local warehouse, and then merge the dev into myBranch.
If there is a conflict, please resolve the conflict in the work area. Finally, submit the revised file
//先将自己工作区代码改动放到本地仓
ga .
gst
gc -m'修改了某文件'
gst
//更新代码
git checkout dev
git pull origin dev(简写git pull)
//将dev合并到自己分支里
git checkout myBranch
git merge dev
gst
//若有冲突,修改冲突,再提交所修改的文件
git add 修改的文件
gst
gc -m'手动合并'
gst
gp
Comments: For the workspace, it is equivalent to modifying the code first and then updating the code, that is, editing on the old code. prone to conflict
Method Two
First push the workspace changes into the temporary stack, then the workspace is clean, then update the workspace, and then merge dev into myBranch.
Finally, the previous workspace changes are popped up. If there is a conflict at this time, resolve the conflict first, and then submit the modified file.
git stash//将工作区改动压入栈中
//更新代码
git checkout dev
git pull
//将dev合并到myBranch里
git checkout myBranch
git merge dev
//弹出之前工作区改动
git stash pop
//若有冲突,解决冲突,并提交修改的文件
ga 某文件
gst
gc -m'合并代码'
gst
gp
Comments: It is equivalent to update the code first, and then edit it, with less conflicts. And git stash pop is very convenient to see where there are conflicts
Finally, the person in charge merges the code on the small partner branch into dev, and you're done!