make-branch
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/make-branch — Move changes from main to a new branch
/make-branch — 将改动从main分支迁移至新分支
When you've been working on (or a random placeholder branch like a petname) and want to PR, this skill creates a well-named feature branch and moves your commits and uncommitted changes onto it.
main当你一直在分支(或类似随机占位分支,如自动生成的宠物名分支)上工作,且想要发起PR时,此工具会创建一个命名规范的特性分支,并将你的提交记录和未提交改动迁移至该分支。
mainWorkflow
工作流程
1. Assess the situation
1. 评估当前情况
Run these in parallel:
bash
git branch --show-current
git log origin/main..HEAD --oneline
git diff --stat
git diff --cached --statClassify the current branch:
- /
main— proceed with the branch-out flow (Cases A/B/C below).master - Placeholder / petname branch — proceed with the in-place rename flow (Case D). A branch is a placeholder if any of these match:
- Petname pattern: (two lowercase words joined by a single hyphen, no slash, no digits — e.g.
^[a-z]+-[a-z]+$,useful-pony,sound-midge). Claude Code and similar tools auto-generate these.novel-aphid - Generic placeholder name: ,
wip,tmp,temp,test,scratch, or similar.work - The user passes an argument asking to rename (e.g. "because this branch is petname", "rename this branch").
- Petname pattern:
- Already-conventional branch — a branch matching is well-named. Abort and tell the user to use
^(feat|fix|refactor|docs|test|chore|perf|ci)/.+directly./make-pr - Protected branches (,
develop,dev,staging,production) — abort; don't touch these.release/*
Abort if there's nothing to move — no commits ahead of and no uncommitted changes (only applies to the branch-out flow; the rename flow can proceed with only committed work).
origin/main并行运行以下命令:
bash
git branch --show-current
git log origin/main..HEAD --oneline
git diff --stat
git diff --cached --stat对当前分支进行分类:
- /
main— 继续执行分支迁出流程(见下文案例A/B/C)。master - 占位/宠物名分支 — 执行原地重命名流程(案例D)。若分支符合以下任一特征,则判定为占位分支:
- 宠物名格式:(两个小写单词用单个连字符连接,无斜杠、无数字 — 例如
^[a-z]+-[a-z]+$,useful-pony,sound-midge)。Claude Code及类似工具会自动生成此类分支名。novel-aphid - 通用占位名称:,
wip,tmp,temp,test,scratch或类似名称。work - 用户传入重命名请求参数(例如“因为这是宠物名分支”、“重命名此分支”)。
- 宠物名格式:
- 已符合规范的分支 — 分支名匹配格式,命名规范。终止操作并告知用户直接使用
^(feat|fix|refactor|docs|test|chore|perf|ci)/.+。/make-pr - 受保护分支(,
develop,dev,staging,production) — 终止操作;请勿改动此类分支。release/*
若无内容可迁移则终止 — 若没有领先于的提交记录,且无未提交改动(仅适用于分支迁出流程;重命名流程可仅针对已提交内容执行)。
origin/main2. Generate a branch name
2. 生成分支名
Analyze the commits and/or diff to understand the theme of the changes. Generate a branch name:
- Format: (e.g.,
<type>/<short-kebab-description>,feat/add-type-annotations,fix/url-parsing)refactor/simplify-session - Types: ,
feat,fix,refactor,docs,test,chore,perfci - Keep it under 50 chars, descriptive, no issue numbers unless obvious
分析提交记录和/或差异内容,理解改动主题。生成分支名需遵循:
- 格式:(例如
<type>/<short-kebab-description>,feat/add-type-annotations,fix/url-parsing)refactor/simplify-session - 类型:,
feat,fix,refactor,docs,test,chore,perfci - 长度控制在50字符以内,描述清晰,除非明确必要否则不包含问题编号
3. Move changes to the new branch
3. 将改动迁移至新分支
Handle three cases:
Case A: Commits ahead of origin/main + uncommitted changes
bash
git stash --include-untracked
git branch <branch-name>
git reset --hard origin/main
git switch <branch-name>
git stash popCase B: Commits ahead of origin/main only (clean working tree)
bash
git branch <branch-name>
git reset --hard origin/main
git switch <branch-name>Case C: Uncommitted changes only (no commits ahead)
bash
git switch -c <branch-name>Case D: Already on a placeholder / petname branch — rename in place
Safe, non-destructive. Preserves all commits and working-tree state; no stash needed.
bash
git branch -m <old-placeholder> <branch-name>If the placeholder branch was already pushed to origin, also update the remote:
bash
git push origin :<old-placeholder> <branch-name>
git push -u origin <branch-name>处理以下三种情况:
案例A:领先于origin/main的提交记录 + 未提交改动
bash
git stash --include-untracked
git branch <branch-name>
git reset --hard origin/main
git switch <branch-name>
git stash pop案例B:仅存在领先于origin/main的提交记录(工作树干净)
bash
git branch <branch-name>
git reset --hard origin/main
git switch <branch-name>案例C:仅存在未提交改动(无领先提交)
bash
git switch -c <branch-name>案例D:当前已在占位/宠物名分支上 — 原地重命名
安全且无破坏性。保留所有提交记录和工作树状态;无需使用stash。
bash
git branch -m <old-placeholder> <branch-name>若占位分支已推送到origin,还需更新远程分支:
bash
git push origin :<old-placeholder> <branch-name>
git push -u origin <branch-name>4. Verify and report
4. 验证并反馈
bash
git branch --show-current
git log origin/main..HEAD --oneline
git status --shortPrint a summary:
- Branch name created
- Number of commits moved
- Working tree status
- Suggest running next
/make-pr
bash
git branch --show-current
git log origin/main..HEAD --oneline
git status --short输出总结信息:
- 创建的分支名称
- 迁移的提交数量
- 工作树状态
- 建议下一步执行
/make-pr
Guidelines
指导原则
- Always fetch before comparing: first
git fetch origin main - Never force-delete or lose commits — the stash+reset approach is safe
- If doesn't exist (e.g., fresh repo), use
origin/mainor abort with a messageorigin/master - Don't commit uncommitted changes — just move them to the new branch as-is
- Pick a branch name that would make sense as a PR title prefix
- 对比前先执行fetch:先运行
git fetch origin main - 绝不强制删除或丢失提交记录 — stash+reset的方式是安全的
- 若不存在(例如新仓库),使用
origin/main或终止操作并提示信息origin/master - 无需提交未改动内容 — 直接将其原样迁移至新分支
- 选择可作为PR标题前缀的分支名