What is it?
The Gitflow workflow is a strict branching model that provides a robust framework for managing large projects and teams. This workflow assigns specific responsibilities to named branches in the repository and defines how and when they should interact.
How it works
The five main branches used in this workflow include
-
master
branch -
develop
branch -
feature
branch -
release
branch -
hotfix
branch
Master Branch
The sole responsibily of this branch is to contain the release
and hotfix
history of the project. Only the release
and hotfix
branches can be merged into this branch.
Develop Branch
This branch is derived from the master
branch at the beginning of the project.
git init
git checkout -b develop
git push -u origin develop
It serves as the integration branch for all features contained in respective feature
branches.
Feature Branch
When a new feature is to be developed, a feature
branch is created from develop
.
git checkout develop
git checkout -b feature-branch
git push -u origin feature-branch
When development is complete, it is merged back into the develop
branch.
git checkout develop
git merge feature-branch
feature
branches are never allowed to interact directly with the master
branch
Release Branch
When it's time for a new release, a release
branch is created from develop
. This branch is used to integrate all the features - since the last release - and fix any bugs that may arise
git checkout develop
git checkout -b release/2.2.3
A version number is usually appended to each release
branch upon creation. When the release is ready, it is merged into the master
branch.
git checkout master
git merge release/2.2.3
The release
branch must be merged back into develop
because it will contain relevant changes from the last release that should be integrated back into develop
git checkout develop
git merge release/2.2.3
Hotfix Branch
When a bug is detected in the master
branch, a hotfix
or maintenance
branch is created from the master
branch to resolve the issues.
git checkout master
git checkout -b hotfix-branch
Afterwards, it is merged into both master
and develop
branches
git checkout master
git merge hotfix-branch
git checkout develop
git merge hotfix-branch
Summary
A good demonstration of the Gitflow workflow can be seen below
git init
git checkout -b develop
git checkout -b feature_branch
# work happens on the feature branch - multiple feature branches can be created
git checkout develop
git merge feature_branch
git checkout -b release/0.1.0
# work happens on the release branch
git checkout master
git merge release/0.1.0
git checkout develop
git merge release/0.1.0
# if issues arise in master
git checkout master
git branch -d hotfix_branch
# work happens on the hotfix branch
git checkout master
git merge hotfix_branch
git checkout develop
git merge hotfix_branch
Top comments (0)