preface

If your project is multi-functional at the same time; If your project is going agile iterations, need the ability to release at any time; If your test environment is not enough and your code is often overwritten; If you need to merge code after CI/CD automatic implementation; Or the current branch management scheme is so complex that it relies on human conventions or tools; Then the new branch management scheme proposed in this paper may be very suitable, welcome to discuss a more suitable solution.

Common branch management schemes

This part will analyze Git Flow, GitHub Flow and GitLab Flow three popular workflow models and summarize the advantages and disadvantages and application scenarios of each model.

Git Flow

The flow chart

Branches and Functions

  • Trunk master: Holds the online version of the code
  • Develop: A collection of functional branches that have been developed and are waiting for release
  • Create a branch from Develop, review it, test it, and return it to Develop
  • Release: The release branch is created from Develop, used as a helper when publishing, and merged into master and Develop after publishing
  • Hotfix: Fix branches created from master, used as a helper when fixing online issues, and then add master and Develop to the hotfix

Advantages and disadvantages analysis

Advantages:

  • Independent functional branches, do not interfere with each other, independent development, testing
  • When Feature branches are long, advance Release can be avoided
  • Ability to release multiple versions

Disadvantages:

  • When multiplayer development requires testing/pre-validation of the environment, the environment is not enough and the code is often overwritten
  • The habit of relying heavily on regular team releases does not lend itself to agile iterations
  • Arguably the most complex of the processes, the cost of learning is slightly higher
  • Dealing with PR/MR can take a lot of time if there are a lot of releases

GitHub Flow

The flow chart

Branches and Functions

  • Trunk master: Holds the online version of the code
  • Feature: The development branch is created from master, and can be released directly after code review and testing
  • Hotfix: Fix branches created from master, same as feature

Advantages and disadvantages analysis

Advantages:

  • It is easy to operate and can be published continuously

Disadvantages:

  • The process is relatively simple, not suitable for multi-functional development
  • You need developers with test-driven development skills who can run local tests before doing PR
  • It can be painful to maintain multiple versions at the same time

GitLab Flow

The flow chart

Branches and Functions

  • Trunk Master: A collection of functional branches that have been developed and are waiting for release
  • Feature: The development branch is created from the master, and after completion, it is merged back to the master after code review and testing
  • Publish production: The pre-production branch accepts only Mr Initiated from master; The production release branch accepts only Mr Initiated from pre-Production. Ensure that the overall merge order is one-way.
  • Hotfix: similar to feature, merge back to master and then merge into all release branches

Advantages and disadvantages analysis

Advantages:

  • The solution covers both “release” and “continuous release”
  • Be able to distinguish between different environment versions and support the test team well

Disadvantages:

  • In order to cope with pre-delivery and online environments, there are secondary branches in addition to the master
  • Hotfix processing has become similar to feature branches, with multiple cherry-picks required to create from master to turn

New branch management scheme

As described above, each branch management scheme has some disadvantages and may have different trial scenarios. Our group’s business is multi-functional iteration, so we tried Git Flow before, but finally gave it up due to some problems of agile iteration. Later, on the basis of many practices, we precipitated a new flow, which solved some common problems of agile iteration. At the same time, combined with Devops hook, it can realize the automatic release and deployment of the corresponding branch code MR of each environment. Most importantly: simple enough!!

The flow chart

Branches and Functions

master

  • Branch Meaning: A logical branch on a line
  • Access conditions: All logic functions are accepted and ready to go online. Join master from release or Hotfix branch, and combine Devops to realize automatic CI/CD
  • MR Source: release, hotfix
  • MR Target: Unlimited

develop

  • Branch meaning: just for the development of the test environment, that’s all, do not join dev to the development branch!! The same applies when you have multiple environments, such as Develop for development and QA for test
  • Access conditions: When the code development is completed and requires joint debugging or testing, all features can be combined even if they are not launched at the same time. Conflicts may need to be solved, but they must be solved eventually
  • MR source: feature
  • MR Target: who goes by
  • Timing of MR delivery: After all process tests are completed, MR will be delivered and the project manager will be admitted
  • Progress synchronization principle: Synchronize the master branch in a timely manner

feature-*

  • Branch meaning: The development branch of requirement function must be pulled based on master in general, and the branch with dependencies can be built based on other dependent feature branches.
  • Access conditions: Branch committers confirm whether to log in by themselves
  • MR Source: master, or release if it goes online that day
  • MR Target: Develop, release
  • When to send MR: Send MR when the development is completed
  • Progress synchronization principle: Synchronize the Master branch in a timely manner

release-*

  • Branch meaning: The function branch sends the pre-release environment in the format of release-20201230, which is used to merge the features that need to be online on the day. After the pre-release environment acceptance is complete, add the master online package
  • Access conditions: Function branches that need to be online on the same day
  • MR source: feature
  • MR Target: master
  • Send MR timing: when the code function is finally confirmed and the pre-send environment is needed

hotfix-*

  • Branch Meaning: emergency repair branch for online problems, in the format of hotfix-20201230. After the pre-release environment acceptance is completed, the branch is connected to the master and sends the online package. If there is a release branch that needs to go online that day, it can also go online together with Release
  • Access conditions: Branch committers confirm whether to log in by themselves
  • MR Source: Unlimited
  • MR Target: Master and release
  • Send MR timing: send MR when the repair development is completed, send the test environment at the same time, and close after the test is completed

Advantages and disadvantages analysis

Advantages:

  • To solve the multi-functional development needs to send test environment verification, test environment is not enough, the code is often covered and other problems
  • In theory, code can be released at any time, perfect for agile iterations
  • Combined with Devops hook, automatic CI/CD can be realized after each environment corresponding branch code MR
  • Simple enough to practice and promote

Disadvantages:

  • Conflicts may need to be resolved multiple times
  • The proposed branch is inconsistent with the online branch

Here are the two disadvantages:

The problem of the first conflict is that we may need to solve the conflicts between features when we send requirements for test and pre-send, and the cost is not high in the case of few conflicts. For highly collaborative projects, to prevent multiple conflicts in each environment, it is recommended to pull a branch from master, such as feature-merge, to resolve conflicts at once.

The second question may be of concern to you, because generally speaking, the test function is consistent with the online function. Now the test environment is not pure, but may be coupled with other functions under test. I understand that it is necessary to consider the scenario where functions interact with each other in the testing process. We have had such a case before, where two requirements were related, but we found that the related part was not developed until the launch, leading to the launch risk. The sooner this part of the problem is exposed during the testing phase, the better. This will benefit project risk management and test integrity. If you’re worried about code purity, there’s also a pre-release environment in the process that does just that: regression and bottom out.

conclusion

This paper describes the common use posture and advantages and disadvantages of Git workflow, and puts forward a new Git branch management scheme, hoping to help everyone.

Finally, just to put it broadly, we are bytedance – the business Cash front end team. As bytedance’s realization center, the commercial products department is responsible for realizing the revenue of the entire product matrix of Bytedance, such as Douyin, Toutiao, watermelon and Huoshan. Team details: Business realization front end team. Our position includes many bases in North China/Shanghai/Hangzhou/North America. We suggest that you send your resume directly to the email, and there will be a special person to send the resume to the target entry base ~ direct email: [email protected]