Git Flow#
In this short article, we will explain the concept of Git Flow briefly.
Git Flow is one of the most wide known workfows. The others are GitHub Flow, GitLab Flow, One Flow and so on.
Git Flow is based on two long-lived/permanent branches.
main/master, we usemainin this article. It is the de facto production, all codes will be merged into this branch sooner or later.develop, pre-production. When we complete the features coding, thefeaturebranch will be merged intodevelop.
There are also some other types of branches besides these two long-lived ones.
-
Feature branches, for developing new features in the next release cycle. Feature branches always use
developas their parent branch and when a feature is complete, it gets merged back intodevelop. Features should never interact directly withmain. -
Hotfix branches, maintenance or
hotfixbranches are used to quickly patch production releases. This is the only branch that should fork directly off ofmain. As soon as the fix is complete, it should be merged into bothmainanddevelop. -
Release branches, are based on a ready to release
developbranch, which meansdevelophas acquired enough features for a release or a predetermined release date is approaching. So, only bug fixes, documentation generation, and other release-oriented tasks should go in this branch. Once it's ready, thereleasebranch gets merged intomainand tagged with a version number. It should also be merged back intodevelop, which may have progressed since the release was initiated.
Advantages#
- The two long-lived branches are clean during the release cycle.
- The branches naming method is easy to understand.
- It is widely supported by most of the git tools.
- It is well designed for maintaining multiple production versions in the project.
Shortcomings#
- The Git history grows, which lacks of readability.
- The long-lived feature branches require more collaboration to merge and have a higher risk of deviating from the trunk branch which can also introduce conflicting updates.
Summary#
Git Flow is one of many styles of Git workflows, it is great for a release-based software workflow. And it offers a dedicated channel for hotfixes to production.
The overall flow of Git Flow is:
- A
developbranch is created frommain - A
releasebranch is created fromdevelop - Feature branches are created from
develop - When a
featureis complete, it is merged into thedevelopbranch - When the
releasebranch is done, it is merged intodevelopandmain - If an issue in
mainis detected, ahotfixbranch is created frommain - Once the
hotfixis complete, it is merged to bothdevelopandmain