Git Flow Workflow
Git Flow branching model — feature, 发布, and hotfix 分支 for structured 发布.
你将学到
- Git Flow branching model and 它的分支类型
- 如何 feature, 发布, and hotfix 分支工作
- 当 Git Flow 是 appropriate 对比 simpler workflows
- git-flow extension commands
概念讲解
What Is Git Flow?
Git Flow is a branching model proposed by Vincent Driessen in 2010. It defines a strict set of branch types and rules for how they interact, designed for projects with scheduled releases (like versioned software products).
The Branch Types
Git Flow uses five types of branches:
主要— production-ready code. Every commit on main is a release. Tags mark versions.develop— the integration branch for features. Contains the latest delivered features for the next release.- **
feature/*** — branched fromdevelop, merged back todevelop. Each new feature gets its own branch. - **
发布/*** — branched fromdevelop, merged to both主要anddevelop. Prepares a release (version bumps, last fixes). - **
hotfix/*** — branched from主要, merged to both主要anddevelop. Fixes production bugs urgently.
The Workflow
main: A-------------------M---H--- (tags: v1.0, v1.1)
\ / \ /
develop: B---F---G---R---/
\ /
feature/x: C---D---F (merged to develop)
- Start a feature:
git checkout -b feature/登录 develop - Finish a feature: merge into
develop - Start a release:
git checkout -b 发布/1.1 develop - Finish a release: merge into
主要anddevelop, tag on主要 - Hotfix:
git checkout -b hotfix/bug 主要, fix, merge into主要anddevelop
The git-flow Extension
The git-flow extension provides shortcut commands:
git flow init # initialize Git Flow
git flow feature start login # create feature/login from develop
git flow feature finish login # merge feature into develop
git flow release start 1.1 # create release/1.1
git flow release finish 1.1 # merge to main + develop, tag
git flow hotfix start bug # create hotfix/bug from main
git flow hotfix finish bug # merge to main + develop, tag
Install it with brew 安装 git-flow (macOS) or your package manager.
Git Flow vs GitHub Flow
Git Flow is powerful but complex. For many projects, a simpler model works better:
GitHub Flow (simpler):
- One
主要branch - Feature branches off
主要 - Pull requests to merge into
主要 - Deploy from
主要continuously
Trunk-Based Development (simplest):
- Everyone commits to
主要(or short-lived branches) - Feature flags for incomplete work
- Continuous deployment
When to Use Git Flow
Git Flow is a good fit for:
- Versioned products with scheduled releases (e.g., desktop apps, libraries)
- Multiple maintained versions (you need to hotfix old releases)
- Teams that need structure and clear release phases
It is overkill for:
- Web apps with continuous deployment
- Small teams that can communicate informally
- Projects where releases happen multiple times per day
Choose the simplest workflow that works for your team. You can always adopt Git Flow later if you need more structure.
示例代码
# --- Initialize Git Flow (creates develop branch, etc.) ---
git flow init
# --- Feature branch workflow ---
git flow feature start user-auth
# ... work on the feature ...
git add .
git commit -m "feat: add user authentication"
git flow feature finish user-auth
# merges feature/user-auth into develop, deletes the feature branch
# --- Release workflow ---
git flow release start 1.2.0
# bump version numbers, last-minute fixes
git commit -am "chore: bump version to 1.2.0"
git flow release finish 1.2.0
# merges release into main AND develop, tags v1.2.0
# --- Hotfix workflow (urgent production bug) ---
git flow hotfix start critical-security-bug
# fix the bug
git commit -am "fix: patch security vulnerability"
git flow hotfix finish critical-security-bug
# merges into main AND develop, tags the hotfix
# --- Without the extension (manual Git Flow) ---
git checkout develop
git checkout -b feature/new-api
# ... work ...
git checkout develop
git merge --no-ff feature/new-api
git branch -d feature/new-api
# Release branch manually
git checkout develop
git checkout -b release/2.0.0
# ... version bump, fixes ...
git checkout main
git merge --no-ff release/2.0.0
git tag -a v2.0.0 -m "Release 2.0.0"
git checkout develop
git merge --no-ff release/2.0.0
git branch -d release/2.0.0
Shows git-flow extension commands for features, 发布, and hotfixes, plus equivalent manual Git commands. 键 insight 是那个发布合并到 两者都主要 and develop, and hotfixes 做相同. 这个 ensures 主要 and develop stay in sync.
动手试一试
- CI/CD YAML Generator
Generate 流水线 for 发布 and hotfix 分支.
- .gitignore Generator
Keep 你的发布分支 clean 使用 proper .gitignore.
常见错误
错误写法
Using Git Flow for continuously deployed web app
正确做法
Git Flow's 发布分支添加 overhead 那个做 不 pay off for web apps deployed 多个次数每 day. For continuous 部署, use GitHub Flow (feature 分支 + PRs 到主要) or Trunk-Based Development. Reserve Git Flow for versioned products 使用 scheduled 发布.
错误写法
Forgetting 到合并发布/hotfix 分支后面到 两者都主要 and develop
正确做法
In Git Flow, 发布 and hotfix 分支必须是 合并到 BOTH 主要 and develop. 如果你 仅合并到 主要, develop 将是 missing 更改 and 它们将 不是 in 下一个发布. git-flow extension handles 这个 automatically; 如果做 它 manually, 总是合并到 两者都.
相关资源
相关速查表
- Git Cheatsheet
Git Flow 分支类型 and workflow commands.
练习 Git Flow Workflow
2 个练习
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。