GitLab Flow介绍

GitLab Flow

核心概念: 

  1. 主线开发 (master) → 只开发「已确认」的功能
  2. 测试环境 (pre-production)验证没问题才能进入正式环境
  3. 正式环境 (production)稳定运行,所有变更都经过测试

简单来说

  1. 写程式 → master
  2. 测试确认 → pre-production
  3. 正式上线 → 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)

  1. 打开 GitLab,建立 MR (feature-login → master)
  2. 请求 Code Review(其他人帮忙看程式码)
  3. 通过 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-bugproduction 
最后,把 production 的修正 同步回 pre-productionmaster

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

 这样确保 productionpre-productionmaster 都同步最新修正!

 最终总结

动作分支步骤
开发feature-*建立分支 → 开发功能 → 提交 MR
测试pre-productionmaster 合併 → 测试验证
上线productionpre-production 确认后合併
修 Bugfix-*直接从 production 修正,然后同步回 master

这样做的好处

  1. 比 GitFlow 简单,不需要 develop 分支
  2. 适合 CI/CD,确保 production 只包含测试通过的版本
  3. 避免 Merge 过多分支,让团队流程顺畅
  4. 修 Bug 直接从 production 修,确保稳定性

 

 

元哥的笔记

关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章