Git Flow 是历史上最著名、最完整的一套 Git 分支管理流程(2010 年由 Vincent Driessen 提出)。
虽然现在很多团队改用更轻量的 GitHub Flow 或 Trunk-Based,但大厂、金融、传统企业、需要严格发版控制的项目仍在广泛使用 Git Flow。下面给你 2025 年还能实战的完整 Git Flow 指南。

1. Git Flow 的 5 个核心分支(必须背下来)

分支名 作用 是否长期存在 保护级别
main 线上正在运行的版本(绝对稳定) 永久 最高
develop 下一版本正在开发的主分支(集成分支) 永久
feature/* 新功能开发分支 临时
release/* 发版准备分支(测试、修复 bug、准备上线) 临时
hotfix/* 线上紧急修复分支 临时

2. 完整流程图(经典五边形)

                  ┌───────────────┐
                  │   hotfix/*     │ ← 紧急修复
                  └───────┬───────┘
                          ↑
           ┌─────────── main ◄──────────┐
           │              ↑             │
           │              │             │
      develop ◄──────── release/*       │
           ↑              │             │
           │              ↓             │
      feature/*  ←──────────────────────┘

3. 推荐使用 git-flow 工具(一条命令全自动)

2025 年最推荐做法:不要手动敲,直接装 git-flow 扩展,所有操作一条命令搞定!

# macOS
brew install git-flow

# Ubuntu/Debian
sudo apt install git-flow

# Windows(用 Git Bash 或 Scoop)
scoop install git-flow

初始化(只做一次):

git flow init
# 基本一路回车即可,默认就是:
# main     → main
# develop  → develop

4. 每天真实使用的 git-flow 命令(直接复制)

场景 命令 说明
开始一个新功能 git flow feature start login 从 develop 创建 feature/login 分支
结束一个功能(合并回 develop) git flow feature finish login 自动合并 + 删除本地分支 + 切回 develop
发布新版本(准备上线) git flow release start 1.8.0 从 develop 创建 release/1.8.0 分支
测试完要上线了 git flow release finish 1.8.0 自动合并到 main + 打 tag + 合并回 develop
线上突然发现严重 bug git flow hotfix start login-bug 从 main 创建 hotfix/login-bug 分支
紧急修复完上线 git flow hotfix finish login-bug 自动合并到 main + develop + 打 tag

5. 手动不装 git-flow 也能做(对应命令)

git-flow 命令 等价手动命令(不装插件也能用)
git flow feature start xxx git switch -c feature/xxx develop
git flow feature finish xxx git switch develop
git merge --no-ff feature/xxx
git branch -d feature/xxx
git flow release start 1.8.0 git switch -c release/1.8.0 develop
git flow release finish 1.8.0 git switch main
git merge --no-ff release/1.8.0
git tag -a v1.8.0 -m “Release 1.8.0”
git switch develop
git merge --no-ff release/1.8.0
git branch -d release/1.8.0
git flow hotfix start bug123 git switch -c hotfix/bug123 main
git flow hotfix finish bug123 git switch main
git merge --no-ff hotfix/bug123
git tag -a v1.7.1 -m “Hotfix 1.7.1”
git switch develop
git merge --no-ff hotfix/bug123
git branch -d hotfix/bug123

6. 2025 年真实公司还在用的 Git Flow 变种(推荐)

很多团队觉得原始 Git Flow 太重,做了简化:

简化点 做法
不再使用 release 分支 直接在 develop 打 tag 发布
所有 PR 都 squash 合并 保持 main 和 develop 历史超级干净
强制 main 和 develop 受保护 只能通过 PR 合并
hotfix 仍然保留 线上紧急修复还是最快的方式

7. Git Flow vs GitHub Flow 对比(你必须知道)

项目类型 推荐流程 原因
移动端/App(发版周期长) Git Flow 需要严格测试、发版控制
Web 项目(可灰度、秒发) GitHub Flow main 永远可发布,特性分支直接 PR
创业公司、开源项目 GitHub Flow 简单、快速
银行、医疗、传统企业 Git Flow 流程审计、合规要求

一句话结论(2025 年真实情况)

需要我给你一份:

  • 彩色打印版 Git Flow 流程图 + 命令速查表(PDF)
  • 公司级 Git Flow 规范模板(含分支命名、PR 要求)

随时说一声,我立刻发你!

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐