Community写作与编辑github.com

gener8v/gener8v.claude-skills.engineering

在第一次编辑之前,将工作放在正确的分支上。查找基础分支,从当前远程顶端创建一个命名良好的分支,并为每个代理设置一个工作树以实现并行工作。适用于对跟踪文件的任何更改开始时,例如“开始处理 issue 42”、“修复这个拼写错误”、“为这三个工单设置分支”,或在你启动编辑代码的子代理之前。不用于创建或合并 PR(github-pr-merge),也不用于历史重写和其他危险的 git 命令(git-safety)。

gener8v.claude-skills.engineering 是什么?

这是一个 Git 分支管理技能,旨在确保每项更改都在独立的分支上进行,避免直接在主分支上提交。它会自动检测基础分支(根据仓库说明、远程默认分支或向用户确认),并从远程最新 tip 创建新分支,确保不受本地过时分支影响。支持并行工作,通过工作树为每个代理分配独立分支,避免文件冲突。同时提供分支命名规范(如 `fix/42-null-session-crash`)和小步提交指南,并集成了推送前的测试链。适用于 Claude Code、Cursor 或 Codex 等 AI 编码代理,作为修改代码前的标准流程。需要配合 `engineering:github-pr-merge` 和 `engineering:git-safety` 技能使用。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/gener8v/gener8v.claude-skills.engineering/tree/HEAD/skills/git-branching

Installed? Explore more 写作与编辑 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Git 分支管理

每项更改都应在自己的分支上进行。这包括一行修复和没有 issue 的更改。不要在主分支上提交。

1. 查找基础分支

使用第一个给出答案的源:

  1. 仓库说明。 阅读 CLAUDE.md、CONTRIBUTING.md 和 .github/ 文档。如果它们命名了某个基础分支或集成分支,就使用它。
  2. 远程默认分支。
    git symbolic-ref --short refs/remotes/origin/HEAD   # 输出 origin/<名称>
    gh repo view --json defaultBranchRef -q .defaultBranchRef.name
    
  3. 歧义情况。 如果远程也有 develop 或 development 分支,并且没有文档说明哪个是基础分支,请询问用户。不要猜测。

当集成分支(例如 develop)是基础分支时,针对已发布版本的 hotfix 应从默认分支开始。仅当用户将工作称为 hotfix 时才使用。

2. 检查当前所在位置

git status --porcelain
git rev-parse --abbrev-ref HEAD
  • 如果工作树有不是你做的更改,则停止。询问用户如何处理它们。
  • 如果你已在一个用于同一工作的分支上,则保持在该分支上。
  • 如果你在基础分支上且有自己未提交的编辑,则移动它们:git switch -c <name> 会将它们保留在工作树中。

3. 从远程 tip 创建分支

git fetch origin --prune
git switch -c <name> origin/<base>
git log -1 --oneline

从 origin/<base> 开始,意味着本地过时的基础分支不会造成影响。不要运行 git pull 来“赶超”基础分支。没有必要这样做。

4. 命名分支

如果仓库有约定,则使用它。否则使用 <type>/<ref>-<slug>:

部分值
typefeat、fix、docs、chore、refactor、test、release、hotfix
refIssue 编号 (42)、流水线工单 (ticket-007) 或留空
slug两到五个小写单词,用连字符连接

示例:fix/42-null-session-crash、feat/ticket-007-search-filters、docs/readme-install-steps。

5. 工作期间

  • 以每个提交都是独立有意义的步骤进行小步提交。使用祈使句写主题,不超过 72 个字符。在正文中说明原因。
  • 不要在提交信息中添加 Co-Authored-By: Claude 标签。这是 gener8v 的规定。
  • 在第一次推送之前,你可以 rebase 到 origin/<base>。分支推送之后,改用合并基础分支到该分支的方式。对已推送分支进行 rebase 会重写历史,而 engineering:git-safety 对此进行限制。
  • 使用一个在第一次失败时停止的管道链进行推送:
    set -o pipefail
    git fetch origin && <test command> 2>&1 | tail -n 40 && git push -u origin HEAD
    
    没有 set -o pipefail,| tail 会隐藏其之前命令的退出码。切勿在没有它的情况下通过 tail 管道传递 git 命令或测试命令。

并行工作

对于两个或更多同时编辑代码的代理,在启动任何代理之前阅读 resources/parallel-work.md。简而言之:从基础分支创建一个批处理分支,从批处理分支为每个代理创建一个工作树和一个分支,并且没有两个代理处理相同的文件。

完成条件

  • 你在一个名称清晰的分支上,并且它从当前的 origin/<base> 开始。
  • git status 没有显示属于其他人的更改。

相关技能

  • engineering:github-pr-merge:工作完成后打开 PR。
  • engineering:git-safety:关于强制推送、删除分支等命令的审批规则。
  • engineering:github-issue-workflow:issue 或流水线工单的完整生命周期。它首先调用此技能。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

gener8v/gener8v.claude-skills.engineering

Find and run a project's test, lint, type-check, build and dev-server commands, read the results correctly, and seed a throwaway database when UI work needs realistic data. Never seeds the project's real or default database. Use before 'run the tests', 'lint this', 'does it build', 'start the app so I can see it', 'seed some demo data', and before you claim that a change works. Not for deployment or CI pipeline design; use the project's own deploy tooling for those.

gener8v/gener8v.claude-skills.engineering

Create or top up a project's documentation set: list what exists, let the user choose which document types to add, collect one shared fact sheet from the code, write the documents (in parallel when there are several), then check them against each other and against the code. Use when asked to 'bootstrap the docs', 'start the documentation', 'we have no README or ARCHITECTURE', or 'fill in the missing docs'. Not for the per-commit update of existing documents (documentation-sync), and not for gener8v pipeline documents (gener8v:brownfield and gener8v:planning make those).

gener8v/gener8v.claude-skills.engineering

Before a commit, find every document that describes what the change touched and update it in the same commit, or confirm in one line that no document needs a change. Catches stale text, missing documentation and facts kept in two places. Use before any commit or PR, and when asked 'are the docs up to date', 'update the docs for this change' or 'did I miss a README change'. Not for creating a documentation set or filling large gaps (documentation-bootstrap), and not for gener8v pipeline documents under .gener8v/, which the pipeline skills own.

gener8v/gener8v.claude-skills.engineering

Approval gate for git commands that destroy work or skip checks: force-push, --no-verify, signing bypass, reset --hard, clean -f, discarding uncommitted edits, branch or tag deletion, rewriting pushed commits and push --mirror. Each one needs the user's explicit approval at that moment; an earlier approval never carries over. Also covers a secrets check before a commit and what to do when a secret is already committed. Use before any of these commands, or when asked to 'force push', 'skip the hooks', 'throw away my changes' or 'delete that branch'. Not for normal branching (git-branching) or the PR flow (github-pr-merge).

相关技能