Git工作流最佳实践让团队协作更高效大家好我是蔓蔓。在大厂时我们团队一直使用规范化的Git工作流这对于多人协作非常重要。今天我来和大家分享Git工作流的最佳实践。Git Flow分支策略main └── develop ├── feature/user-login ├── feature/payment ├── hotfix/bug-123 └── release/v1.0.0分支说明# main/master - 生产环境代码随时可部署 git checkout main # develop - 开发分支集成所有功能 git checkout develop # feature/* - 功能分支从develop切出合并回develop git checkout -b feature/new-feature develop # release/* - 发布分支准备发布新版本 git checkout -b release/v1.0.0 develop # hotfix/* - 紧急修复从main切出合并回main和develop git checkout -b hotfix/critical-bug main开发流程# 1. 创建功能分支 git checkout develop git pull origin develop git checkout -b feature/my-feature # 2. 开发并提交 git add . git commit -m feat: add my feature # 3. 推送到远程 git push origin feature/my-feature # 4. 创建Pull Request代码审查 # 5. 合并到develop git checkout develop git merge --no-ff feature/my-feature git push origin develop # 6. 删除功能分支 git branch -d feature/my-feature git push origin --delete feature/my-featureGitHub Flow更简单的工作流# 1. 从main创建分支 git checkout main git pull origin main git checkout -b feature/my-feature # 2. 提交变更 git add . git commit -m feat: add new feature git push origin feature/my-feature # 3. 创建Pull Request # 4. 代码审查合并到main git checkout main git pull origin main git merge --no-ff feature/my-feature git push origin main # 5. 部署main分支Commit Message规范Conventional Commits# 格式 type(scope): subject # type类型 feat: 新功能 fix: 修复bug docs: 文档更新 style: 代码格式不影响功能 refactor: 重构 perf: 性能优化 test: 测试相关 chore: 构建/工具变动 # 示例 git commit