git-branch-worktree-convention
Skill0 starsChanged 30 days agoApache-2.0View on GitHub
Project-level task branch and worktree convention. Use whenever creating or validating task branches, selecting a change integration branch, recording SOURCE_BRANCH, merging a completed task, or protecting the original checkout.
In this repository16 other files it gives its agents.
- backend-reliability-guidelinesSkill
- code-review-specSkill
- commitSkill
- context-handoffSkill
- dddSkill
- design-to-developmentSkill
- development-workflowSkill
- frontend-interaction-guidelinesSkill
- knowledge-notesSkill
- logging-boundariesSkill
- prodflowSkill
- project-context-syncSkill
- project-hygieneSkill
- rest-api-documentationSkill
- service-deploymentSkill
- task-closeout-auditSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
32 rules. About 0 are common, 20 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈20
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Use one confirmed integration branch for a change, then create every task branch from that branch and merge every completed task back into …
- Distinctive: line 42
Follow the more specific authority when instructions overlap.
- Distinctive: line 51
Read the checked-out branch with git branch --show-current.
- Very specific: line 52
Stop if Git reports a detached HEAD.
- Very specific: line 53
Ask the user: 当前分支 <branch>,是否以它作为本次 change 的集成分支?
- Very specific: line 54
After confirmation, record that exact branch name as INTEGRATION_BRANCH in the current change/task context.
- Very specific: line 62
Every task branch for the change starts from INTEGRATION_BRANCH.
- Distinctive: line 63
Every completed task merges back into that same branch.
- Very specific: line 64
Before starting the next task, switch to INTEGRATION_BRANCH.
- Distinctive: line 66
Do not replace the integration branch because the operator happens to switch branches mid-change.
- Distinctive: line 72
Use one task branch per OpenSpec task or other independently verifiable task.
- Very specific: line 95
All tasks belonging to the same change use the same <change-id> and the same INTEGRATION_BRANCH.
- Very specific: line 97
Do not use 📦 parent branches.
- Distinctive: line 105
Before creating a task branch, confirm it matches the regex and that no local branch or worktree already uses the name.
- Distinctive: line 110
All task worktrees live under:
- Distinctive: line 140
Run these commands from the clean checkout of the confirmed integration branch:
- Very specific: line 179
All task edits, tests, and commits occur inside TASK_WORKTREE.
- Very specific: line 184
Read .source_branch from the task worktree instead of guessing the target.
- Distinctive: line 199
If the integration checkout has unrelated uncommitted changes or the merge conflicts, stop.
- Distinctive: line 203
Only after the ancestry check succeeds and the task worktree is clean:
- Very specific: line 220
Before creating task T2:
- Distinctive: line 223
Verify it is clean and contains the previous task merge.
- Very specific: line 224
Create T2 from INTEGRATION_BRANCH, not from T1 and not from an older commit.
- Distinctive: line 245
Read code and Git history.
- Distinctive: line 253
Run task tests that write build, coverage, or log artifacts.
- Distinctive: line 256
All task implementation and verification runs in the task worktree.
- Distinctive: line 297
Use a task branch and dedicated worktree for every independently verifiable implementation task.
- Distinctive: line 301
Create every task branch from the confirmed integration branch.
- Distinctive: line 303
Start each later task from the integration branch after prior task merges.
- Distinctive: line 304
Do not create or use parent aggregation branches.
- Distinctive: line 305
Do not edit task files or create task commits from the original checkout.
- Distinctive: line 306
Do not delete a task worktree or branch until its merge is verified by the ancestry check.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Branch and Worktree Convention
Use one confirmed integration branch for a change, then create every task
branch from that branch and merge every completed task back into it. dev is
only an example: the integration branch is the branch the user confirms when
the first task begins.
This skill defines branch names, source-branch traceability, and integration
rules. using-git-worktrees owns safe worktree creation mechanics;
development-workflow owns when each gate occurs; and commit owns commit
message format.
Model
confirmed integration branch (for example: dev)
├─ task 1 branch -> verify -> merge back into dev
├─ task 2 branch -> verify -> merge back into dev
└─ task N branch -> verify -> merge back into dev
end state: remain on dev, which contains every merged taskThere is no parent/change branch. Do not create a branch merely to aggregate task branches. The integration branch is the only aggregation point.
Authority and Conflicts
| Concern | Authoritative source |
Task branch name, integration source, SOURCE_BRANCH, merge target, original-checkout protection | This skill |
| Worktree creation safety and baseline verification | using-git-worktrees |
| Workflow timing, task gates, and final integration | development-workflow |
| Commit message format | commit |
| Force-push, reset, hook skipping, and destructive Git operations | Project/global Git rules |
Follow the more specific authority when instructions overlap. Do not duplicate or weaken another skill's safety rules.
Integration Branch
Select it once
At the first task of a change:
- Read the checked-out branch with
git branch --show-current. - Stop if Git reports a detached
HEAD. - Ask the user:
当前分支 <branch>,是否以它作为本次 change 的集成分支? - After confirmation, record that exact branch name as
INTEGRATION_BRANCHin the current change/task context.
The confirmed branch can be dev, release/*, main, or another valid
working branch. Never assume that a branch literally named dev exists.
Keep it fixed for the change
- Every task branch for the change starts from
INTEGRATION_BRANCH. - Every completed task merges back into that same branch.
- Before starting the next task, switch to
INTEGRATION_BRANCH; it now includes the preceding task's merge. - Do not replace the integration branch because the operator happens to switch branches mid-change. Ask before changing it; changing it starts a new integration boundary.
Task Branch Naming
Use one task branch per OpenSpec task or other independently verifiable task.
features/✅<change-id>-T<task-num>--<task中文名>
fixes/✅<change-id>-T<task-num>--<子问题中文名>Examples:
features/✅CHG-001-T1--支付模块改造
features/✅CHG-001-T2--库存扣减逻辑
fixes/✅BUG-055-T1--添加乐观锁Rules:
✅(U+2705) identifies a task branch.<change-id>is uppercase letters, a hyphen, then digits, such asCHG-001orBUG-055.-T<task-num>identifies the task number.- The Chinese task description contains at least three Chinese characters and has no spaces or shell-special characters.
- All tasks belonging to the same change use the same
<change-id>and the sameINTEGRATION_BRANCH. - Do not use
📦parent branches.
Validation regex:
^(features|fixes)/✅[A-Z]+-[0-9]+-T[0-9]+--[一-龥]{3,}$Before creating a task branch, confirm it matches the regex and that no local branch or worktree already uses the name.
Worktree and Source Recording
All task worktrees live under:
.claude/worktrees/<full-task-branch-name>/The worktree root must be ignored by Git before creation. Use the safety and
directory checks from using-git-worktrees before running the commands below.
Record the merge target before any task-owned work begins. In the task
worktree, create .source_branch containing exactly:
SOURCE_BRANCH=<INTEGRATION_BRANCH>For example, a task created from dev contains:
SOURCE_BRANCH=dev.source_branch is local worktree metadata. It tells the completion step the
only branch that may receive this task's merge.
Create a Task Branch and Worktree
git worktree add -b creates and checks out the branch in one operation. It
is the worktree-safe equivalent of git checkout -b <task-branch>.
Run these commands from the clean checkout of the confirmed integration branch:
INTEGRATION_BRANCH=$(git branch --show-current)
TASK_BRANCH='features/✅CHG-001-T1--支付模块改造'
TASK_WORKTREE=".claude/worktrees/$TASK_BRANCH"
# Confirm INTEGRATION_BRANCH with the user before the first task.
test -n "$INTEGRATION_BRANCH" || { echo 'detached HEAD'; exit 1; }
test -z "$(git status --porcelain)" || { echo 'integration checkout is dirty'; exit 1; }
git show-ref --verify "refs/heads/$INTEGRATION_BRANCH"
if git show-ref --verify --quiet "refs/heads/$TASK_BRANCH"; then
echo "task branch already exists: $TASK_BRANCH"
exit 1
fi
test ! -e "$TASK_WORKTREE" || exit 1
git worktree add "$TASK_WORKTREE" -b "$TASK_BRANCH" "$INTEGRATION_BRANCH"Then, before the first edit or commit, write the source record in the new worktree:
TASK_GIT_DIR=$(git -C "$TASK_WORKTREE" rev-parse --git-dir)
mkdir -p "$TASK_GIT_DIR/info"
printf '.source_branch\n' >> "$TASK_GIT_DIR/info/exclude"
printf 'SOURCE_BRANCH=%s\n' "$INTEGRATION_BRANCH" > "$TASK_WORKTREE/.source_branch"Verify the setup:
git worktree list --porcelain
git -C "$TASK_WORKTREE" branch --show-current
git -C "$TASK_WORKTREE" status --short
cat "$TASK_WORKTREE/.source_branch"All task edits, tests, and commits occur inside TASK_WORKTREE.
Merge a Completed Task
Merge only after the task's required tests, review, and workflow gates pass.
Read .source_branch from the task worktree instead of guessing the target.
TASK_WORKTREE='.claude/worktrees/features/✅CHG-001-T1--支付模块改造'
TASK_BRANCH=$(git -C "$TASK_WORKTREE" branch --show-current)
INTEGRATION_BRANCH=$(cut -d= -f2 "$TASK_WORKTREE/.source_branch")
# Use the clean checkout/worktree where the integration branch is checked out.
git switch "$INTEGRATION_BRANCH"
test -z "$(git status --porcelain)" || { echo 'integration checkout is dirty'; exit 1; }
git show-ref --verify "refs/heads/$INTEGRATION_BRANCH"
git merge --no-ff "$TASK_BRANCH"
git merge-base --is-ancestor "$TASK_BRANCH" "$INTEGRATION_BRANCH"If the integration checkout has unrelated uncommitted changes or the merge conflicts, stop. Preserve those changes and resolve the issue before claiming the task integrated.
Only after the ancestry check succeeds and the task worktree is clean:
test -z "$(git -C "$TASK_WORKTREE" status --porcelain)" || {
echo 'task worktree is dirty'
exit 1
}
git worktree remove "$TASK_WORKTREE"
git branch -d "$TASK_BRANCH"
git switch "$INTEGRATION_BRANCH"The final git switch is intentional: after every task, and after the last
task, remain on the confirmed integration branch.
Start the Next Task
Before creating task T2:
- Return to
INTEGRATION_BRANCH. - Verify it is clean and contains the previous task merge.
- Create
T2fromINTEGRATION_BRANCH, not fromT1and not from an older commit. - Record the same
SOURCE_BRANCH=<INTEGRATION_BRANCH>inT2's worktree. - Repeat the normal test, review, merge, and cleanup gates.
This makes the dependency chain explicit:
integration branch at start
-> task T1 -> merge into integration branch
-> task T2 starts from updated integration branch
-> merge into integration branchOriginal Checkout Protection
Once a task worktree exists, the checkout where the integration branch is checked out is read-only for that task.
Allowed there:
- Read code and Git history.
- Inspect status, logs, diffs, and blame.
- Switch to the integration branch for the verified merge and cleanup.
Forbidden there:
- Edit task-owned files.
- Create task commits.
- Run task tests that write build, coverage, or log artifacts.
- Change task-related dependencies or configuration.
All task implementation and verification runs in the task worktree. Confirm the current directory before task work:
git rev-parse --path-format=relative --git-common-dir 2>/dev/null | grep -q worktreesAn exit code of 0 means the command runs from a linked worktree.
Validation Checklists
Before the first task
- The current checkout is on a named branch, not detached
HEAD. - The user confirmed the current branch as
INTEGRATION_BRANCH. - The integration checkout is clean.
- The task branch name matches the task regex.
- No existing branch or worktree has the task name.
.claude/worktrees/is ignored.
Before each task
- Current branch is the confirmed
INTEGRATION_BRANCH. - The integration checkout is clean.
- The task branch is created from the current
INTEGRATION_BRANCHtip. - The task worktree records
SOURCE_BRANCH=<INTEGRATION_BRANCH>. - Edits, tests, and commits run only in the task worktree.
Before task cleanup
- The task's focused and broader verification gates passed.
- The task worktree is clean.
.source_branchidentifies an existing integration branch.- The integration checkout is clean before merging.
git merge --no-ff <task-branch>completed successfully.git merge-base --is-ancestor <task-branch> <integration-branch>succeeds.- The task worktree and branch are removed only after the successful merge.
- The final checkout is
INTEGRATION_BRANCH.
Non-Negotiable Rules
- Use a task branch and dedicated worktree for every independently verifiable implementation task.
- Confirm the integration branch once at the beginning of a change; do not silently change it later.
- Create every task branch from the confirmed integration branch.
- Merge every task only into the
SOURCE_BRANCHrecorded in its worktree. - Start each later task from the integration branch after prior task merges.
- Do not create or use parent aggregation branches.
- Do not edit task files or create task commits from the original checkout.
- Do not delete a task worktree or branch until its merge is verified by the ancestry check.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

