跳到正文
Skillpedia
通用编程40k · #7120

conventional-branch

它能做什么

这个工具可以帮你为新的 Git 分支命名。分支就像代码中相互独立的工作线。它能确保分支名称遵循特定的格式,便于更好地组织工作。

适用场景

  • ✓当你开始开发一个新功能时。
  • ✓当你修复 bug 时。
  • ✓当你要整理非代码类任务时。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/conventional-branch/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/conventional-branch/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我想创建一个分支,用来添加新的登录页面。”

每周 5 个新技能,1 分钟读完。

工作原理

你需要说明要做什么(比如添加登录功能)以及工作类型(比如 feature)。工具会按照规则给出建议的分支名称,如果你愿意,它还可以直接帮你创建这个分支。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Conventional Branch

Create Git branches that follow the Conventional Branch specification — a simple, consistent convention for naming Git branches.

Branch Name Format

<type>/<description>

Branch Types

Type Alias Purpose
feature/ feat/ New features or enhancements
bugfix/ fix/ Bug fixes
hotfix/ — Urgent production fixes
release/ — Release preparation (dots allowed in version: release/v1.2.0)
chore/ — Non-code tasks (deps, docs, config)

Trunk Branches

main, master, and develop are trunk branches — they do not use a prefix. Never create new branches with the same names as trunk branches; branch off them instead.

Naming Rules

  • Lowercase only — no uppercase letters anywhere
  • Alphanumerics, hyphens, and dots — a-z, 0-9, -, .
  • Dots allowed only in release/ version descriptions (e.g., release/v1.2.0)
  • No underscores, spaces, or special characters
  • No consecutive hyphens (--), dots (..), or hyphen-dot adjacency (-. or .-)
  • No leading or trailing hyphens or dots in the description

Valid Examples

main
master
develop
feature/add-login-page
feat/add-login-page
bugfix/fix-header-bug
fix/header-bug
hotfix/security-patch
release/v1.2.0
chore/update-dependencies
feature/issue-123-new-login

Invalid Examples

Branch Problem
Feature/Add-Login Uppercase letters
feature/new--login Consecutive hyphens
feature/-new-login Leading hyphen
feature/new-login- Trailing hyphen
release/v1.-2.0 Hyphen adjacent to dot
fix/header bug Space
fix/header_bug Underscore
unknown/some-task Unknown prefix type

Description Guidelines

  • Use kebab-case with 2-5 words
  • Be descriptive but concise (~50 chars total)
  • Good: add-oauth-login, fix-header-overflow, update-ci-config
  • Bad: fix-bug, new-feature

Workflow

Follow these steps:

Step 1 — Determine Branch Type

Ask the user (if not already clear):

  • Branch type — default to feature when uncertain
  • Brief description — what the branch is for

If the user mentions a ticket or issue number, include it in the description (e.g., feature/issue-123-add-oauth).

Step 2 — Validate the Name

Check the assembled name against the Naming Rules above. If any rule fails, fix it:

  • Lowercase everything
  • Replace underscores and spaces with hyphens
  • Collapse consecutive hyphens
  • Strip leading/trailing hyphens

Step 3 — Detect the Base Branch

Different repos use different trunk branches. Detect which one this repo uses:

# Prefer the remote's default branch
git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's|^origin/||'

If that returns nothing, check which trunk branch exists locally (priority order: develop, main, master):

for b in develop main master; do
  git show-ref --verify --quiet "refs/heads/$b" && echo "$b" && break
done

Step 4 — Create and Checkout

git checkout <base>
git pull origin <base>
git checkout -b <type>/<description>

Step 5 — Confirm

Tell the user:

  • The branch name that was created
  • That they are now on the new branch
  • Remind them: git push -u origin <branch-name> when ready

Relationship with Conventional Commits

Conventional Branch complements Conventional Commits:

Conventional Branch Typical Conventional Commit
feature/add-login feat: add login page
bugfix/fix-header fix: header overflow on mobile
chore/update-deps chore: bump lodash to 5.0
release/v1.2.0 chore: release v1.2.0

Align the branch type with commit types where possible (e.g., feature/* branches with feat: commits).

常见问题

什么是 Git 分支?

可以把分支想象成项目的一个副本,你可以在上面尝试新想法或修复问题,而不会影响主版本。之后,你可以再把修改合并回去。

分支名称为什么重要?

统一的命名能让你和团队成员快速了解这个分支在做什么,使工作更有条理,也更容易跟进。

分支类型有哪些?

常见的类型包括 'feature'(新功能)、'bugfix'(缺陷修复)、'hotfix'(紧急修复)、'release'(准备发布版本)和 'chore'(其他杂项任务)。

详情

作者的原始描述

Create Git branches following the Conventional Branch specification (feature/, bugfix/, hotfix/, release/, chore/). Use when creating a new branch, naming a branch, or checking whether a branch name complies with the spec.

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7120
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能