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 usemain
in 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, thefeature
branch 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
develop
as their parent branch and when a feature is complete, it gets merged back intodevelop
. Features should never interact directly withmain
. -
Hotfix branches, maintenance or
hotfix
branches 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 bothmain
anddevelop
. -
Release branches, are based on a ready to release
develop
branch, which meansdevelop
has 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, therelease
branch gets merged intomain
and 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
develop
branch is created frommain
- A
release
branch is created fromdevelop
- Feature branches are created from
develop
- When a
feature
is complete, it is merged into thedevelop
branch - When the
release
branch is done, it is merged intodevelop
andmain
- If an issue in
main
is detected, ahotfix
branch is created frommain
- Once the
hotfix
is complete, it is merged to bothdevelop
andmain