Git branch management and naming conventions

First, branch classification

  • Git master branch (reserved branch) : master, develop

Main branches: Master and Develop. The former is used for official release and the latter for daily development.

  • Git secondary branches (temporary branches) : feature, Release, fixbug

In addition to the permanent branches, there are temporary branches for release development for specific purposes. There are three main types of temporary branches:

  • Feature branching
  • The pre-release branch
  • The fixbug branch

All three branches are temporary and should be removed once you’re done with them so that the permanent branches of the code base are always just Master and Develop.

Two, branch introduction

1. Master branch

The code base has one and only one main branch on which all official releases are made available to users. Git’s default Master branch is the Master branch, which is automatically set up. After the repository is initialized, development is done in the Master branch by default.

2. Develop branch

The main branch should only be used to distribute major releases, and daily development should be done on the other branch. We call the development branch, Develop. This branch can be used to generate the latest overnight version of the code (NIGHTLY). If you want to formally publish, merge the Develop branch on the Master branch.

  • Create a branch

Git creates the Develop branch

git checkout -b develop master
Copy the code
  • Release branch

Publish the Develop branch to Master:

Git merge --no-ff DevelopCopy the code

What does the no-ff parameter mean? By default, Git performs a “fast-farward merge” that points the Master branch directly to the Develop branch.

With the –no-ff parameter, a normal merge is performed to create a new node on the Master branch. This is recommended to ensure clear version evolution.

3, function branch feature

A feature branch is a branch of Develop that develops a specific feature and then merges into Develop. The name of a feature branch can be named as feature-*.

  • Create a branch

Command to create a functional branch:

git checkout -b feature-xxx develop
Copy the code
  • Merging branches

After development, merge the functional branches into the Develop branch:

git checkout develop

git merge --no-ff feature-xxx
Copy the code
  • Delete the branch

Delete feature branch:

git branch -d feature-xxx
Copy the code

4. Pre-release branch release

Pre-release branch, which means we may need to have a pre-release version to test before we release the official version (i.e. before merging into the Master branch).

The pre-release branch is separated from the Develop branch and must be merged into the Develop and Master branches after pre-release. It can be named release- star.

  • Create a branch

Command to create a pre-published branch:

Git checkout -b release-2.5 developCopy the code
  • Merging branches

After verifying that there are no problems, merge the command to the master branch:

Git checkout master git merge --no-ff release-2.5Copy the code

To merge into the Develop branch:

Git Checkout develop Git merge --no-ff release-2.5Copy the code
  • Delete the branch

Finally, delete the command for the pre-published branch:

Git branch - d release 2.5Copy the code

Branch fixbugs

Bug repair branch. After the software is officially released, bugs will inevitably occur. At this time, you need to create a branch for bug repair.

The branch is separated from the Master branch. After the patch is complete, merge into the Master and Develop branches. It can be named in the form fixbug-*.

  • Create a branch

Create a bug-fixing branch command:

Git checkout -b fixbug-0.1 masterCopy the code
  • Merging branches

When the patch is complete, merge the command to the master branch:

Git checkout master git merge --no-ff fixbug-0.1 git tag -a 0.1Copy the code

To merge into the Develop branch:

Git Checkout develop Git merge --no-ff fixbug-0.1Copy the code
  • Delete the branch

Finally, remove the bug-fixing branch command:

Git branch fixbug - 0.1 - dCopy the code

Third, summarize and conclude

Finally, review the big picture at the beginning and understand the life cycle of the two main branches and the three auxiliary branches, which branch starts from which branch.

References:

Git branch management policy

Git branch management is an art