Git分支命名规范与最佳实践
常见命名方案
1. 功能分支
feature/<简短描述>
feature/user-authentication
feature/add-payment-method
2. Bug 修复分支
bugfix/<问题描述>
bugfix/login-crash
bugfix/404-error
3. 发布分支
release/<版本号>
release/v1.2.0
release/2024-spring
4. 热修复分支
hotfix/<紧急问题描述>
hotfix/critical-security-fix
hotfix/production-bug
5. 实验性分支
experiment/<实验名称>
experiment/new-ui-design
experiment/ai-integration
最佳实践原则
✅ 推荐的命名方式
-
使用小写字母(避免大小写混淆)
-
用连字符分隔单词(推荐)
feature/add-dark-mode # ✅ 好 feature/addDarkMode # ❌ 避免 -
保持名称简短但有描述性
-
包含相关票号(如果使用 Jira 等工具)
feature/TICKET-123-add-search bugfix/ABC-456-fix-null-pointer
❌ 应避免的命名
-
避免使用特殊字符(
!@#$%^&*()) -
避免空格
-
避免过长的名称
-
避免使用含糊的名称如
test、fix、update
团队协作建议
1. 统一前缀
团队应商定一致的前缀:
feat/ # 功能
fix/ # 修复
docs/ # 文档
style/ # 样式
refactor/ # 重构
test/ # 测试
chore/ # 杂项
2. 包含开发者信息(可选)
feat/john-user-profile
fix/sarah-login-issue
3. 日期格式(如果需要)
feature/20240115-new-dashboard
hotfix/20240120-security-patch
实际示例
<span>git</span> checkout <span>-b</span> feat/add-user-avatar-upload
<span>git</span> checkout <span>-b</span> fix/responsive-layout-issue
<span>git</span> checkout <span>-b</span> refactor/payment-module
<span>git</span> checkout <span>-b</span> docs/update-api-documentation