An elegant Git branching practice

overview

Git branches are the soul of git design. How to design Git branches to make the development go into the soul? This is the place where our project was approved. Generally speaking, the branch design needs to meet the following points:

1> Avoid mutual interference of development functions during team development

2> Various branches: scientific management such as development, testing, online, bugs, backups, labels, etc.

Let's introduce a best practice for git branch management for small and medium-sized projects.

Git flow

Vincent Driessen , the inventor of the Git flow process , Portal:

A successful Git branching model » nvie.comIn this post I present a Git branching strategy for developing and releasing software as I’ve used it in many of my projects, and which has turned out to be very successful.https://nvie.com/posts/a-successful-git-branching-model/

Conclusions first, explanations later

commonly used branches

Master branch

The main branch, the initial point of the project is initiated by this branch, and the subsequent branch is used as the project version marking branch, which can be understood as a backup branch, from which all versions of the project can be traced back. Any project version can be pulled from this branch and run smoothly. Note: The Master branch does not allow programmers to write code here.

Develop branch

The development branch is initially created in the Master branch, and the branch where all the development code of the team is merged. In addition, the Develop branch maintains the latest code of the project.

Feature branch

Function branch, a new branch created based on the Develop branch, used for the development of new functions/modules. When the development is complete, it needs to be merged back to the Develop branch. This branch is the exclusive branch of programmers and does not exist in the team's source code repository.

Release branch

When you need to release a new version, create a Release branch based on the Develop branch. At this point, it should be noted that all Feature branches belonging to this version need to be merged into the Develop branch. After the Release branch is successfully created, test the version and fix bugs. After completion, the code needs to be merged into the Master and Develop branches. Merging into the Master branch will mark the Master to indicate a new version. When merging into the Develop branch, it should be noted that other feature branches other than this version are not allowed to be merged into the Develop branch before the Release branch is released.

Hotfix branch

When the project is launched and a new bug is found during operation, a Hotfix needs to be created based on the Master. After the Hotfix is ​​completed, we merge back to the Master and Develop branches, so the changes of the Hotfix will enter the next Release version.

Development case

Step 1: After the project is established, the project manager initializes the project, creates a Master branch, and creates a Develop branch based on the Master branch

 Step 2: To add function A to the project, it needs to be implemented in 2 steps: function A1, function A2

 Programmer Xiaoming creates Xiaoming's Feature branch based on the Develop branch, and completes the steps of function A1 and function A2. After the development is completed, it is merged into the Develop branch. At this time, the Develop branch has function A.

Step 3: At the same time, the project wants to try to innovate and try to realize function B

  Programmer Xiaohong creates the Xiaohong Feature branch based on the Develop branch, trying to implement function B

Step 4: Function A needs to be launched urgently, and function B is suspended at this time

1> After completing function A, merge it into Develop

2> Function A needs to go online, create a Release branch on the basis of Develop, and complete testing/debugging/bug correction in this branch

3> After confirming the completion, merge the Release branch code into the Develop branch, merge into the Master branch, and mark Tag2

4> Before the Release is merged back to the Development branch, the new Feature branch is not allowed to be merged back to the Develop branch.

5> After merging into the Master and Develop branches, it can be deleted or not

Step 5: Function B is developed and needs to be released

The logic is the same as step 4, so I won’t expand on it here.

Step 6: After the function AB (Tag3 version) is launched, a bug needs to be fixed

1> When a bug occurs, create a Hotfit branch based on the Master branch

2> Complete the bug modification in the Hotfit branch, after the test passes, merge the code into the Master branch, and label it Tag3.1

3> Complete the bug modification in the Hotfit branch. After the test is passed, merge the code into the Develop branch to ensure that the Develop branch code is up-to-date.

last full version

 

epilogue

The above is the entire operation process of the Git flow mode. The advantage is that it is clear and controllable, but the disadvantage is that the operation is complicated. Two long-term branches need to be maintained, the Develop branch and the Master branch. This results in frequent branch switching for each operation.

Guess you like

Origin blog.csdn.net/langfeiyes/article/details/126068779#comments_25947428