Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Git Flow

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:


Git Flow Branching Model

master Branch:

develop Branch:

feature Branch:

release Branch:

hotfix Branch:

Branch Operation Principles

Git Flow Command Examples

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

Disadvantages

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.