branch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBranch
分支
Start work on a new git branch, optionally in a new worktree.
创建新的Git分支,也可选择在新工作区中创建。
Arguments
参数
Accepts one of the following as arguments:
- Issue number: e.g., — fetches the issue title and derives the branch name
/branch 123 - Description: e.g., — derives the branch name from the text
/branch add shellcheck support - Worktree flag: append or
--worktreeto create a git worktree instead of a regular branch-w
Examples:
- — branch from issue #123
/branch 123 - — branch from description
/branch add dark mode toggle - — worktree from issue #123
/branch 123 --worktree - — worktree from description
/branch fix login redirect -w
接受以下任意一种作为参数:
- 问题编号:例如,—— 获取问题标题并生成分支名称
/branch 123 - 描述文本:例如,—— 根据文本内容生成分支名称
/branch add shellcheck support - 工作区标记:追加 或
--worktree以创建Git工作区,而非普通分支-w
示例:
- —— 基于编号#123的问题创建分支
/branch 123 - —— 根据描述文本创建分支
/branch add dark mode toggle - —— 基于编号#123的问题创建工作区
/branch 123 --worktree - —— 根据描述文本创建工作区
/branch fix login redirect -w
Branch Naming
分支命名规则
Derive the branch name using this format:
text
<type>/<issue-number?>-<slug>- type: Infer from context — ,
feat/,fix/,chore/,docs/,refactor/,perf/,test/ci/- If an issue has labels like →
bug,fix/→enhancement,feat/→documentationdocs/ - If a description starts with a semantic prefix, use it
- Default to if unclear
feat/
- If an issue has labels like
- issue-number: Include only if an issue number was provided
- slug: Lowercase, hyphenated, max ~50 chars, derived from the issue title or
description
- Strip filler words when too long
- e.g., "Add shellcheck support for shell scripts" →
add-shellcheck-support
Examples:
- Issue #123 titled "feat(cli): add watch mode" →
feat/123-add-watch-mode - Issue #45 labeled , titled "Parser crashes on empty input" →
bugfix/45-parser-crashes-on-empty-input - Description "add dark mode" →
feat/add-dark-mode - Description "fix: resolve null pointer" →
fix/resolve-null-pointer
分支名称采用以下格式生成:
text
<type>/<issue-number?>-<slug>- type:根据上下文推断 —— ,
feat/,fix/,chore/,docs/,refactor/,perf/,test/ci/- 如果问题带有标签 → 使用
bug,fix/标签 → 使用enhancement,feat/标签 → 使用documentationdocs/ - 如果描述文本以语义化前缀开头,则直接使用该前缀
- 若无法明确推断,默认使用
feat/
- 如果问题带有
- issue-number:仅在提供问题编号时包含
- slug:由问题标题或描述文本生成,采用小写连字符格式,最长约50字符
- 若内容过长,去除冗余填充词
- 示例:"Add shellcheck support for shell scripts" →
add-shellcheck-support
示例:
- 编号#123、标题为"feat(cli): add watch mode"的问题 →
feat/123-add-watch-mode - 带有标签、标题为"Parser crashes on empty input"的问题 →
bugfix/45-parser-crashes-on-empty-input - 描述文本"add dark mode" →
feat/add-dark-mode - 描述文本"fix: resolve null pointer" →
fix/resolve-null-pointer
Usage — Regular Branch
使用方式 —— 普通分支
When asked to start a new branch (no / flag):
--worktree-w-
Ensure clean state:
- Run — if there are uncommitted changes, warn the user and stop
git status - Do NOT stash or discard changes automatically
- Run
-
Fetch latest:bash
git fetch origin -
Resolve branch name:
- If an issue number was given, fetch it:
gh issue view <number> --json title,labels - Derive the branch name per the naming rules above
- If an issue number was given, fetch it:
-
Create and switch to the branch:bash
git checkout -b <branch-name> origin/main -
Confirm — Print the branch name and a summary of what was done
当需要创建普通分支(不带 / 标记)时:
--worktree-w-
确保工作区干净:
- 执行—— 如果存在未提交的更改,向用户发出警告并终止操作
git status - 切勿自动暂存或丢弃更改
- 执行
-
拉取最新代码:bash
git fetch origin -
确定分支名称:
- 如果提供了问题编号,获取问题信息:
gh issue view <number> --json title,labels - 根据上述命名规则生成分支名称
- 如果提供了问题编号,获取问题信息:
-
创建并切换至分支:bash
git checkout -b <branch-name> origin/main -
确认操作 —— 打印分支名称及操作摘要
Usage — Worktree
使用方式 —— 工作区
When or is specified:
--worktree-w-
Ensure clean state:
- Run — if there are uncommitted changes, warn the user and stop
git status
- Run
-
Fetch latest:bash
git fetch origin -
Resolve branch name (same rules as above)
-
Determine worktree path:
- Place as a sibling directory to the current repo
- Format: (without the type prefix)
<repo-dir>-<slug> - e.g., if repo is at and branch is
~/Code/py-lintro:feat/123-add-watch-mode- Worktree path:
~/Code/py-lintro-123-add-watch-mode
- Worktree path:
- e.g., if branch is :
fix/parser-crash- Worktree path:
~/Code/py-lintro-parser-crash
- Worktree path:
-
Create the worktree:bash
git worktree add -b <branch-name> <worktree-path> origin/main -
Confirm — Print the worktree path, branch name, and how to navigate there:text
Created worktree at ~/Code/py-lintro-123-add-watch-mode Branch: feat/123-add-watch-mode (from origin/main) To start working: cd ~/Code/py-lintro-123-add-watch-mode
当指定或标记时:
--worktree-w-
确保工作区干净:
- 执行—— 如果存在未提交的更改,向用户发出警告并终止操作
git status
- 执行
-
拉取最新代码:bash
git fetch origin -
确定分支名称(规则同上)
-
确定工作区路径:
- 工作区目录与当前仓库同级
- 格式:(不含type前缀)
<repo-dir>-<slug> - 示例:若仓库路径为,分支名称为
~/Code/py-lintro:feat/123-add-watch-mode- 工作区路径:
~/Code/py-lintro-123-add-watch-mode
- 工作区路径:
- 示例:若分支名称为:
fix/parser-crash- 工作区路径:
~/Code/py-lintro-parser-crash
- 工作区路径:
-
创建工作区:bash
git worktree add -b <branch-name> <worktree-path> origin/main -
确认操作 —— 打印工作区路径、分支名称及导航指引:text
Created worktree at ~/Code/py-lintro-123-add-watch-mode Branch: feat/123-add-watch-mode (from origin/main) To start working: cd ~/Code/py-lintro-123-add-watch-mode
Important
注意事项
- NEVER force-delete branches or worktrees
- NEVER stash or discard uncommitted changes — always warn and stop
- Always branch from (freshly fetched)
origin/main - If the branch name already exists, warn the user and ask what to do
- 切勿强制删除分支或工作区
- 切勿暂存或丢弃未提交的更改 —— 始终发出警告并终止操作
- 始终基于(拉取最新版本后)创建分支
origin/main - 如果分支名称已存在,向用户发出警告并询问后续操作