GitLab Flow
核心概念:
- 主线开发 (
master) → 只开发「已确认」的功能 - 测试环境 (
pre-production) → 验证没问题才能进入正式环境 - 正式环境 (
production) → 稳定运行,所有变更都经过测试
简单来说:
- 写程式 →
master - 测试确认 →
pre-production - 正式上线 →
production
1. 下载最新 master
git checkout master
git pull origin master
确保你的程式码是最新的!
2. 开发新功能 (feature-*)
git checkout -b feature-login
git push -u origin feature-login
开发专属自己的功能分支!
3. 撰写程式、提交变更
git add .
git commit -m "feat: 新增登入功能"
git push origin feature-login
开发完成后,推送程式码!
4. 建立 Merge Request(MR)
- 打开 GitLab,建立 MR (feature-login → master)
- 请求 Code Review(其他人帮忙看程式码)
- 通过 Review 后,合併到
master
5. 合併功能分支
git checkout master
git pull origin master # 确保 master 最新
git merge feature-login
git push origin master
合併后,删除已完成的 feature 分支
git branch -d feature-login
git push origin --delete feature-login
6. 测试环境(Pre-Production)
git checkout pre-production
git merge master
git push origin pre-production
合併后,进行最后的测试!
这时 CI/CD 可以自动部署到 pre-production
7. 正式上线(Production)
git checkout production
git merge pre-production
git push origin production
所有测试通过后,才可以併入 production,正式上线!
紧急修正(Hotfix)
如果 正式环境 (production) 发生 Bug:
git checkout production
git checkout -b fix-login-bug
修复 Bug 后:
git add .
git commit -m "fix: 修正登入错误"
git push origin fix-login-bug
建立 MR → 合併 fix-login-bug 到 production
最后,把 production 的修正 同步回 pre-production 和 master:
git checkout pre-production
git merge production
git push origin pre-production
git checkout master
git merge pre-production
git push origin master# 删除修正分支:
git branch -d fix-login-bug
git push origin --delete fix-login-bug 这样确保 production、pre-production 和 master 都同步最新修正!
最终总结
| 动作 | 分支 | 步骤 |
|---|---|---|
| 开发 | feature-* | 建立分支 → 开发功能 → 提交 MR |
| 测试 | pre-production | master 合併 → 测试验证 |
| 上线 | production | pre-production 确认后合併 |
| 修 Bug | fix-* | 直接从 production 修正,然后同步回 master |
这样做的好处
- 比 GitFlow 简单,不需要
develop分支 - 适合 CI/CD,确保
production只包含测试通过的版本 - 避免 Merge 过多分支,让团队流程顺畅
- 修 Bug 直接从
production修,确保稳定性
元哥的笔记

微信扫一扫打赏
支付宝扫一扫打赏