Git Flow
Git Flow is a Git-based branching model designed to help teams better manage and release software.
Git Flow was proposed by Vincent Driessen in 2010, and through a standard set of branch naming and workflows, it makes the development, testing, and release process more orderly and efficient.
Git Flow mainly consists of the following types of branches:master、develop、feature、release、hotfix。
Git Flow Installation
Linux
Debian/Ubuntu:
sudo apt-get install git-flow
Fedora:
sudo dnf install gitflow
sudo apt-get install git-flow
macOS
On macOS, you can use Homebrew to install Git Flow:
brew install git-flow
Installing from source
If your distribution's package manager does not have Git Flow, you can also install it from source:
git clone https://github.com/nvie/gitflow.git
cd gitflow
sudo make install
After installation, you can verify that Git Flow was installed successfully with the following command:
git flow version
Windows
On Windows, you can install Git Flow in the following ways:
-
Using Git for Windows: Git for Windows includes Git Flow. You can from Git for Windows install Git, and then use Git Bash to use Git Flow.
-
Using Scoop: If you use the Scoop package management tool, you can install Git Flow with the following command:
scoop install git-flow
-
Using Chocolatey: If you use the Chocolatey package management tool, you can install Git Flow with the following command:
choco install gitflow
Git Flow Branching Model
master Branch:
- Always remain stable and in a releasable state.
- Each time a new version is released, it is from
developbranch merged tomasterbranch is not executed.
develop Branch:
- used to integrate all development branches.
- represents the latest development progress.
- Feature branches, release branches, and hotfix branches all branch out from here and eventually merge back here.
feature Branch:
- Used to develop new features.
- From the
developbranch; after development is complete, merge back todevelopbranch is not executed. - Naming convention:
feature/feature-name。
release Branch:
- Used to prepare for the release of a new version.
- From the
developbranch; perform final testing and fixes, then merge back todevelopandmasterbranch, and tag it with a version tag. - Naming convention:
release/release-name。
hotfix Branch:
- Used to fix urgent issues.
- From the
masterbranch; after the fix is complete, merge back tomasteranddevelopbranch, and tag it with a version tag. - Naming convention:
hotfix/hotfix-name。

Branch Operation Principles
- Every Commit on the Master branch should be tagged, and the Develop branch is created based on Master.
- After the Feature branch is complete, merge it back into the Develop branch, and usually delete that branch.
- The Release branch is created based on Develop, used for testing and fixing bugs, and after release is merged back into Master and Develop, and tagged to mark the version number.
- The Hotfix branch is created based on Master; after completion it is merged back into Master and Develop, and tagged with Tag 1.
Git Flow Command Examples
- Start a Feature branch:
git flow feature start MYFEATURE - Finish a Feature branch:
git flow feature finish MYFEATURE - Start a Release branch:
git flow release start RELEASE [BASE] - Finish a Release branch: merge into Master and Develop, tag it, and delete the Release branch.
- Start a Hotfix branch:
git flow hotfix start HOTFIX [BASE] - Finish a Hotfix branch: merge into Master and Develop, tag it, and delete the Hotfix branch.
Git Flow Workflow
1. Initialize Git Flow
First, initialize Git Flow in the project. You can use a Git Flow plugin (such as git-flow) to simplify the operation.
git flow init
When initializing, you need to set the branch naming rules and the default branch.
2. Create a feature branch
When starting to develop a new feature, from the develop branch create a feature branch.
git flow feature start feature-name
After development is complete, merge the feature branch back to the develop branch, and delete the feature branch.
git flow feature finish feature-name
3. Create a release branch
When preparing to release a new version, from the develop branch create a release branch.
git flow release start release-name
Perform final testing and fixes on the release branch; when ready to release, merge the release branch back to develop and master branch, and tag it with a version tag.
git flow release finish release-name
4. Create a hotfix branch
When you find an issue that needs an urgent fix, from the master branch create a hotfix branch.
git flow hotfix start hotfix-name
After the fix is complete, merge the hotfix branch back to master and develop branch, and tag it with a version tag.
git flow hotfix finish hotfix-name
Example operations
The following is a comprehensive example of actually using Git Flow.
Initialize Git Flow:
git flow init
Create and finish a feature branch:
git flow feature start new-feature # 开发新功能
git flow feature finish new-feature
Create and finish a release branch:
git flow release start v1.0.0 # 测试和修复
git flow release finish v1.0.0
Create and finish a hotfix branch:
git flow hotfix start hotfix-1.0.1. # 修复紧急问题
git flow hotfix finish hotfix-1.0.1
Advantages and Disadvantages
Advantages
- Clear branching model: Clear branch naming and usage rules make the development process orderly.
- Isolate development and release: The development and release processes are separated, reducing the impact of uncertainty in development on releases.
- Version Management: Each release and fix is tagged with a version tag, making it easy to trace back and manage.
Disadvantages
- Complexity: For small teams or simple projects, Git Flow's branching model may seem too complex.
- Frequent merges: In large teams, frequent branch merges may lead to more merge conflicts.
Git Flow is a structured branch management model that helps teams better manage the software development and release process by defining clear branches and workflows. Although it adds some complexity, for large projects and team collaboration, Git Flow provides powerful support and management capabilities.