Git’s default branch is the master branch. Imagine if all the development is in the master branch. This article will introduce git’s branching strategy

Classification of branch

Normal branch:

  • Master: indicates the primary branch
  • Develop a branch of development

Temporary branch:

  • Feature: a feature branch
  • Release: pre-release branch
  • Fixbug: Fixes the bug branch

The main branch

First, the code base should have one and only one main branch.

All official releases for user use are published on this main branch.

The name of the Master Git branch, which is called Master by default.

It is built automatically, and once the repository is initialized, development is done in the main branch by default.

Development 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.

Git creates the Develop branch

git checkout -b develop master
Copy the code

Publish the Develop branch to Master:

Git merge --no-ff DevelopCopy the code

Function branch

The Develop branch, which is developed from the Develop branch to Develop a specific feature. Once the development is complete, it is incorporated into Develop.

The name of a feature branch can be named as feature-*.

Git creates a functional branch:

git checkout -b feature-x develop
Copy the code

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

git checkout develop
git merge --no-ff feature-x
Copy the code

Delete feature branch:

git branch -d feature-x
Copy the code

Pre-published branch

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.

Git creates a pre-release branch:

git checkout -b release-1.2 develop
Copy the code

If there is no problem, merge into the master branch:

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

Merge into the Develop branch:

git checkout develop
git merge --no-ff release-1.2
Copy the code

Finally, delete the pre-published branch:

git branch -d release-1.2
Copy the code

Bug fixing branch

After the software is released, it is inevitable that there will be bugs. This is where you need to create a branch to fix the bug.

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-*.

Git creates a bug fixing branch:

git checkout -b fixbug-0.1 master
Copy the code

After the patch is complete, merge to the master branch:

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

Merge into the Develop branch:

git checkout develop
git merge --no-ff fixbug-0.1
Copy the code

Finally, remove the “bug fix branch” :

git branch -d fixbug-0.1
Copy the code

Teamwork mode

First, you can try pushing your own changes with git push Origin branch-name.

If the push fails, the remote branch is newer than your local branch and you need to use Git pull to try merging.

If the merge has conflicts, resolve the conflicts and commit locally;

Git push origin branch-name git push origin branch-name

If no tracking information is displayed in Git pull, the link between the local branch and remote branch is not created. Run the git branch –set-upstream branch-name origin/branch-name command.

This is how people work together, and once you get used to it, it’s pretty easy.

Code on among