git branch management and workflow specifications: specific specifications

The previous article introduced the concepts related to git . We can view the status of files, switch between various statuses, create and merge branches, and organize our own commit history through rebase. Through these commands and operations, the operation flow specified in the workflow specification can be completed.

This article introduces the specific specifications, including the division and naming of branches, different types of branches deal with different scenarios, and then introduces the workflow tool git-flow, how to simplify our operations.

branch composition

The master and develop branches have always existed, and the names will not change. Generally, these two branches are not directly modified, but are merged from other branches.

Feature, release, and hotfix are respectively used for feature point development, optimization, specific version testing, and emergency handling of online problems. Multiple branches of the same type will be generated.

The branches are divided as follows:

  • master: It is absolutely consistent with the online version;
  • develop: The development branch, the code merged by the release, feature, and hotfix branches mentioned below;
  • feature: The actual function point development branch, it is recommended to create a new feature for each function, and the functions with associated relationships share a feature branch;
  • release: After each development is completed, the branch created from develop is used as a benchmark for testing;
  • hotfix: This branch is mainly used to fix online bugs;

The naming conventions are as follows:

  • feature branch name: feature/name
  • Release branch name: release/name
  • hotfix branch name: hotfix/name

For example, if there is a requirement to "optimize distributed sessions", a new branch feature/optimize_distributed_session can be created on the basis of the develop branch for development, and merged into the develop branch after the development is completed.

Branch details and processing flow

master branch

The master branch is always consistent with the version running online. Do not modify the master branch directly at any time.

After a version of the release branch and hotfix branch is developed, the code will be merged into the master branch, that is to say, the master branch mainly comes from the release branch and the hotfix branch.

develop branch

The development branch, always keeping the latest completed and bug-fixed code, and creating a feature branch based on this branch when adding new features.

After the release branch and hotfix branch of a version are developed, they will also be merged into the develop branch. In addition, after the development of the feature function of a version is completed, it will also be merged into the develop branch. That is to say, the develop branch comes from the feature, release, and hotfix branches.

feature branch

When new features are developed or existing features are optimized, feature branches are created based on develop. Generally, multiple functions will be developed at the same time, but the launch time may be different. At the appropriate time, a specific feature branch will be merged into the develop branch, and a release branch will be created to enter the testing state.

release branch

When a set of features is developed, it will first be merged into the develop branch, and when it begins to enter the testing phase, a release branch will be created.

The release branch code is used as the benchmark for testing. If there are bugs that need to be fixed during the testing process, the developers will directly fix and submit them in the release branch.

After the test is completed, merge the release branch into the master and develop branches. At this time, the master is the latest code and is used for online.

hotfix branch

When an urgent problem occurs online, it needs to be repaired in time. The master branch is used as the baseline to create a hotfix branch. After the repair is completed, it needs to be merged into the master branch and the develop branch.

Special case handling and attention points

The develop branch already has feature code that has not been launched. At this time, a new feature needs to be launched urgently, but the develop code cannot be launched. What should I do?

  • Create features with master as the baseline, after completion, the code is merged into the master branch;
  • In order to ensure that develop is the latest code, it is necessary to merge from master to develop branch;

Taking develop as the baseline, after creating two feature branches f1 and f2, when f1 and f2 are half developed, what should I do if I find that the two branch codes need to have dependencies?

  • It is best to determine whether the two functions are related before the development starts, and if so, only one branch is created, and the two functions are developed together;
  • If it has already been created, it needs to be merged into a branch;

Be sure to keep the commit history clean and tidy. When merging code, choose merge or rebase according to the situation;

When using rebase, note that once the commit objects in the branch are published to the public repository, do not rebase the branch;

Submit Instructions Specifications:

  • The submission description is best limited to one line, less than 50 characters, briefly describe the update content, and then expand the detailed comments after a blank line;
  • If associated with jira, write the jira address;

git-flow workflow

git-flow tool

The above process will feel a bit complicated when you first come into contact with it. These processes can be automated through the git-flow tool. It is a command line tool that supports various platforms, such as OSX, Linux, Windows, etc.

initialization

Initialize through the git flow init command, in an interactive way, mainly to agree on the naming of branches, it is recommended to use the default value;

Develop new features

git flow feature start f1 adds new features. This operation creates a feature branch based on develop and switches to this branch.

git flow feature finish f1 completes the new feature. This operation will merge the f1 branch into the develop branch, delete the feature branch, and switch back to the develop branch.

git flow feature publish f1 publishes a new branch, publishes a new feature branch to the remote server, and other users can also use this branch.

release version

git flow release start r1 [BASE] Create a release version, [BASE] is based on which branch or commit to release, usually develop.

git flow release publish r1 publishes the release branch, and other colleagues can see this branch and modify some minor issues.

When git flow release finish r1 completes the release branch, it will merge the release branch into the master branch, tag it with the release branch name, merge the release branch into the develop branch, and finally remove the release branch.

Fix online issues

It may be necessary to fix a TAG-tagged production version on the master branch.

git flow hotfix start VERSION [BASENAME] creates a hotfix branch, the VERSION parameter marks the revision version, and [BASENAME] is the version number filled in when finish release.

git flow hotfix finish VERSION, when the emergency fix branch is completed, the code is merged into the develop and master branches. Correspondingly, the master branch is tagged with the revised version.

git flow command

Welcome to scan the QR code below and follow my personal WeChat public account~

love story

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324393108&siteId=291194637