create-branch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate Branch
创建分支
Create a git branch with the correct type prefix and a descriptive name following Sentry conventions.
遵循Sentry规范创建带有正确类型前缀和描述性名称的git分支。
Step 1: Get the Username Prefix
步骤1:获取用户名前缀
Run to get the GitHub username.
gh api user --jq .loginIf the command fails (e.g. not authenticated), ask the user for their preferred prefix.
运行 获取GitHub用户名。
gh api user --jq .login如果命令执行失败(例如未完成身份验证),询问用户偏好的前缀。
Step 2: Determine the Branch Description
步骤2:确定分支描述
If is provided, use it as the description of the work.
$ARGUMENTSIf no arguments, check for local changes:
bash
git diff
git diff --cached
git status --short- Changes exist: read the diff content to understand what the work is about and generate a description.
- No changes: ask the user what they are about to work on.
如果提供了 ,将其作为工作内容的描述。
$ARGUMENTS如果没有传入参数,检查本地变更:
bash
git diff
git diff --cached
git status --short- 存在变更:读取diff内容了解工作内容,生成描述。
- 无变更:询问用户将要开展的工作内容。
Step 3: Classify the Type
步骤3:分类确定类型
Pick the type from this table based on the description:
| Type | Use when |
|---|---|
| New user-facing functionality |
| Broken behavior now works |
| Same behavior, different structure |
| Deps, config, version bumps, updating existing tooling — no new logic |
| Same behavior, faster |
| CSS, formatting, visual-only |
| Documentation only |
| Tests only |
| CI/CD config |
| Build system |
| Repo metadata changes |
| License changes |
When unsure: for new things (including new scripts, skills, or tools), for restructuring existing things, only when updating/maintaining something that already exists.
featrefchore根据描述从下表中选择分支类型:
| 类型 | 使用场景 |
|---|---|
| 面向用户的新功能 |
| 修复异常行为,使其恢复正常工作 |
| 业务行为不变,调整代码结构 |
| 依赖、配置、版本升级、更新现有工具 —— 无新增业务逻辑 |
| 业务行为不变,提升性能 |
| 仅涉及CSS、格式、视觉类改动 |
| 仅涉及文档改动 |
| 仅涉及测试改动 |
| CI/CD配置改动 |
| 构建系统改动 |
| 仓库元数据改动 |
| 许可证改动 |
无法确定类型时:新增内容(包括新脚本、skill、工具)使用,调整现有内容结构使用,仅更新/维护已有内容时才使用。
featrefchoreStep 4: Generate and Propose
步骤4:生成并提议分支名
Build the branch name as .
<username>/<type>/<short-description>Rules for :
<short-description>- Kebab-case, lowercase
- 3 to 6 words, concise but clear
- Describe the change, not file names
- Only use ASCII letters, digits, and hyphens — no spaces, dots, colons, tildes, or other git-forbidden characters
Present it to the user and ask if they want to use it, modify it, or change the type.
分支名格式为 。
<username>/<type>/<short-description><short-description>- 小写kebab-case格式
- 3到6个单词,简洁清晰
- 描述改动内容,而非文件名
- 仅使用ASCII字母、数字和连字符 —— 不允许空格、点、冒号、波浪线或其他git禁止的字符
将生成的分支名展示给用户,询问是否要使用、修改或者调整分支类型。
Examples
示例
| Work description | Branch name |
|---|---|
| Dropdown menu not closing on outside click | |
| Adding search to conversations page | |
| Restructuring drawer components | |
| Updating test fixtures | |
| Bumping @sentry/react to latest version | |
| Adding a new agent skill | |
| 工作描述 | 分支名 |
|---|---|
| 下拉菜单点击外部区域未关闭 | |
| 为会话页面新增搜索功能 | |
| 重构抽屉组件 | |
| 更新测试夹具 | |
| 升级@sentry/react到最新版本 | |
| 新增Agent skill | |
Step 5: Create the Branch
步骤5:创建分支
Once confirmed, detect the current and default branch:
bash
git branch --show-current
git remote | grep -qx origin && echo origin || git remote | head -1
git symbolic-ref refs/remotes/<remote>/HEAD 2>/dev/null | sed 's|refs/remotes/<remote>/||' | tr -d '[:space:]'If fails, fall back to : use the one that exists; if both or neither exist, ask the user.
symbolic-refgit branch --list main masterIf is empty (detached HEAD), show the current commit () and ask whether to branch from it or switch to the default branch first.
git branch --show-currentgit rev-parse --short HEADOtherwise, if the current branch is not the default branch, warn the user and ask whether to branch from the current branch or switch to the default branch first.
If the user wants to switch to the default branch, handle any uncommitted changes appropriately (offer to stash them if present), then run . On any failure, restore stashed changes if applicable and stop.
git checkout <default-branch>Before creating the branch, check that the name doesn't already exist locally or on the remote (). If it does, ask the user to choose a different name.
git show-refCreate the branch:
bash
git checkout -b <branch-name>Restore any stashed changes after the branch is created.
分支名确认后,检测当前分支和默认分支:
bash
git branch --show-current
git remote | grep -qx origin && echo origin || git remote | head -1
git symbolic-ref refs/remotes/<remote>/HEAD 2>/dev/null | sed 's|refs/remotes/<remote>/||' | tr -d '[:space:]'如果执行失败,回退执行:使用存在的分支;如果两个分支都存在或者都不存在,询问用户。
symbolic-refgit branch --list main master如果返回为空(分离头指针状态),展示当前提交(),询问是从该提交切分支还是先切换到默认分支。
git branch --show-currentgit rev-parse --short HEAD否则,如果当前分支不是默认分支,向用户发出警告,询问是从当前分支切分支还是先切换到默认分支。
如果用户选择切换到默认分支,妥善处理所有未提交的变更(如果存在则提议stash暂存),然后运行。如果任何步骤执行失败,恢复已暂存的变更(如果有)并终止操作。
git checkout <default-branch>创建分支前,检查分支名在本地和远端是否已经存在()。如果已存在,要求用户选择其他名称。
git show-ref创建分支:
bash
git checkout -b <branch-name>分支创建完成后恢复所有暂存的变更。