4. Branch Management
4.1 What is a branch?
Branches can be understood as a simple bifurcation, branches grow out on a trunk, the trunk branch often called the master, on the main branch can open many branches out, different people do development on different branches, and finally merged into the master branch, this will not affect each other
4.2.github workflow
github recommended workflow: Click to enter official website address
The first step: according to demand, from the master pulled out a new branch
Step Two: After the new branch development is completed, or when you need to discuss, it initiates a pull request (referred to as PR) to the master.
Step Three: Pull Request is both a notification to let others take note of your request, it is a kind of dialogue we can work together to review and discuss your code. Conversation, you can continue to submit code.
Step Four: Your Pull Request is accepted, merged into master, re-deployment, so you pull out of that branch will be deleted. (Re-deploy the merger are also available.)
4.3 The branch management-related operations
1. Check the branch command
git branch
Results of the:
FIG illustrated in only one branch, master is a main branch, the current front of an asterisk indicates the currently selected master is the main branch
2. Create a branch
git branch newdemo
3. branch switching
git checkout newdemo
Current asterisk in front of newdemo, description of the currently selected branch is newdemo
4. Create a branch, and select a branch
git checkout -b newdemo2
5. merging branches
After a few steps in front, we are now in the master branch have created two branches newdemo and newdemo2
We currently selected branch to branch newdemo2, I am going to write some code on demo2 branch, we create a register.html the file, write some simple code to submit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=, initial-scale=1.0">
<meta ="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>这是newdemo2分支上创建的文件</h1>
</body>
</html>
In this branch, my project file looks like this:
At this point we submit the code to the repository
Next we switch to the master branch:
git checkout master
When we switch to the master branch, it can be observed changes in the project files in a directory, register.html file has been deleted
Finally, we need to newdemo2 merged into the master branch
git merge newdemo2
Results of the:
As can be seen, at the master branch, already exists register.html
6. Delete branch
git branch -d newdemo2
7. The branch pushed on github
git push origin newdemo
螺钉课堂视频课程地址:http://edu.nodeing.com