mcpField
G
git-branch-naming

git-branch-naming

github.com/laurigates开发5973 次安装1 天前更新
代码仓库

关于 git-branch-naming

为开发者和团队提供 Git 分支命名规范与创建指导,涵盖类型前缀、工单编号、描述格式及特殊分支模式,便于保持命名一致并支持自动化。

主要功能

  1. 01规范类型、工单号和描述格式
  2. 02提供分支类型及用途示例
  3. 03给出命名正则校验规则
  4. 04说明工单关联与描述写法
  5. 05涵盖发布、热修复等分支模式

适用场景

  1. 01为新功能或修复创建分支
  2. 02制定团队分支命名约定
  3. 03校验分支名并应用于自动化

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/laurigates/claude-plugins --skill git-branch-naming

安装后在 Claude Code 中输入/git-branch-naming确认已加载。

详细介绍

Git 分支命名约定

统一的分支命名有助于追踪、实现自动化,并让仓库历史更易于浏览。

何时使用此技能

在以下情况下使用此技能……在以下情况下使用其他内容……
创建新的功能/修复分支管理 PR 工作流 → git-branch-pr-workflow
设置团队分支约定提交更改 → git-commit-workflow
讨论命名标准Rebase/合并策略 → git-branch-pr-workflow

分支名称格式

{type}/{issue}-{short-description}
组成部分格式必需示例
type小写前缀是feat、fix
issue问题编号,不带 #如果存在问题123
descriptionkebab-case,2-5 个词是user-authentication
示例
# With issue number (preferred when issue exists)
feat/123-oauth-login
fix/456-null-pointer-crash
chore/789-update-dependencies
docs/101-api-reference

# Without issue number (when no issue exists)
feat/oauth-integration
fix/memory-leak-cleanup
chore/update-eslint-config
refactor/auth-service-split

分支类型

类型用途Conventional Commit
feat/新功能、新能力feat:
fix/修复错误fix:
chore/维护、依赖项、配置chore:
docs/仅限文档docs:
refactor/重构代码,不改变行为refactor:
test/添加/更新测试test:
ci/CI/CD 流水线更改ci:
hotfix/紧急生产环境修复fix:(带紧急标记)
release/准备发布chore: 或 release:

创建分支

标准工作流
# With issue number
git switch -c feat/123-user-authentication

# Without issue number
git switch -c fix/login-timeout-handling

# From specific base
git switch -c feat/456-payment-api main
git switch -c hotfix/security-patch production
验证格式

创建前,先验证格式:

# Branch name regex pattern
^(feat|fix|chore|docs|refactor|test|ci|hotfix|release)/([0-9]+-)?[a-z0-9]+(-[a-z0-9]+)*$

有效:

  • feat/123-user-auth ✓
  • fix/memory-leak ✓
  • chore/update-deps ✓

无效:

  • feature/user-auth ✗(使用 feat,而不是 feature)
  • fix/UserAuth ✗(使用 kebab-case,而不是 PascalCase)
  • my-branch ✗(缺少类型前缀)
  • feat/fix_bug ✗(使用连字符,而不是下划线)

关联问题的最佳实践

何时包含问题编号
场景是否包含问题编号?示例
工作由 GitHub Issues 跟踪是feat/123-add-oauth
工作由外部系统(Jira、Linear)跟踪可选feat/PROJ-456-oauth 或 feat/oauth
探索性/预研工作否spike/auth-approaches
无关联问题的快速修复否fix/typo-readme
Dependabot/自动化 PR否chore/bump-lodash
外部工单系统

对于 Jira、Linear 或其他系统,请使用工单 ID:

feat/PROJ-123-user-dashboard
fix/LINEAR-456-api-timeout
chore/JIRA-789-update-sdk

描述指南

良好的描述
模式示例优点
动作 + 目标add-oauth-login清楚说明正在进行的工作
组件 + 更改auth-service-refactor指明受影响的部分
错误 + 背景null-pointer-user-save描述问题
避免使用
反模式问题更好的写法
fix/bug太含糊fix/123-login-validation
feat/new-feature没有实际含义feat/user-dashboard
feat/john-working-on-stuff描述不清feat/456-payment-flow
fix/issue-123内容重复,且没有描述fix/123-timeout-error
feat/add-new-user-authentication-system-with-oauth太长feat/oauth-authentication
长度指南
  • 最少: 类型/问题编号后至少 2 个词(feat/123-user-auth)
  • 最多: 5 个词,总计约 50 个字符
  • 最佳范围: 3-4 个词(feat/123-oauth-token-refresh)

特殊分支模式

发布分支
release/1.0.0
release/2.1.0-beta
release/v3.0.0-rc1
热修复分支
hotfix/security-vulnerability
hotfix/critical-data-loss
hotfix/production-crash-fix
长期运行的分支

对于持续数周的工作,可考虑添加日期后缀:

feat/123-major-refactor-2026q1
epic/new-billing-system

团队约定

用户名前缀分支(可选)

对于需要关注分支所有权的大型团队:

# Pattern: {user}/{type}/{description}
alice/feat/123-oauth
bob/fix/456-memory-leak

# Or: {type}/{user}-{description}
feat/alice-oauth-integration
fix/bob-memory-leak
受保护的分支模式

为以下分支配置保护规则:

main
master
develop
release/*
hotfix/*

自动化集成

分支名称 → 提交范围

分支类型可为提交信息的范围提供参考:

分支建议的提交信息
feat/123-authfeat(auth): ...
fix/456-apifix(api): ...
docs/readmedocs: ...
CI/CD 触发条件

CI 流水线触发条件的常见模式:

# GitHub Actions example
on:
  push:
    branches:
      - 'feat/**'
      - 'fix/**'
      - 'hotfix/**'
  pull_request:
    branches:
      - main

快速参考

创建分支检查清单
  • 以有效的类型前缀开头(feat/、fix/ 等)
  • 包含问题编号(如果工作有追踪)
  • 描述采用 kebab-case 格式
  • 描述为 2-5 个词
  • 总长度少于 50 个字符
  • 不含下划线、空格或大写字母
命令参考
操作命令
创建分支git switch -c feat/123-description
按类型列出git branch --list 'feat/*'
删除本地分支git branch -d feat/123-description
删除远程分支git push origin --delete feat/123-description
重命名git branch -m old-name new-name
类型选择流程图
Is it a bug fix? → fix/
Is it a new capability? → feat/
Is it documentation? → docs/
Is it maintenance/deps? → chore/
Is it restructuring code? → refactor/
Is it adding tests? → test/
Is it CI/CD changes? → ci/
Is it an emergency? → hotfix/

评论

支持 Markdown