using-git-worktrees
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUsing Git Worktrees (Simplified: Branch-Only Mode)
使用Git Worktrees(简化版:仅分支模式)
Overview
概述
Simplified approach: Create a temporary branch in the current working directory instead of a separate worktree.
Core principle: New branch + safety verification = isolated implementation.
Announce at start: "I'm creating a temporary branch for isolated implementation work."
简化方法: 在当前工作目录中创建临时分支,而非单独的工作树。
核心原则: 新分支 + 安全验证 = 隔离式实现。
启动时告知: "我正在创建一个临时分支用于隔离式实现工作。"
Branch Creation Process
分支创建流程
1. Generate Branch Name
1. 生成分支名称
Use descriptive naming based on the task:
bash
undefined根据任务使用描述性命名:
bash
undefinedFormat: feature/<task-name> or fix/<issue-name>
格式: feature/<任务名称> 或 fix/<问题名称>
branch_name="feature/$(echo "$TASK" | tr ' ' '-' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g' | cut -c1-50)"
undefinedbranch_name="feature/$(echo "$TASK" | tr ' ' '-' | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]//g' | cut -c1-50)"
undefined2. Verify Clean Working Directory
2. 验证工作目录是否干净
bash
undefinedbash
undefinedCheck for uncommitted changes
检查未提交的更改
git status --porcelain
**If uncommitted changes exist:**
- Ask user to stash or commit first
- OR create branch anyway and warn about carrying over changesgit status --porcelain
**如果存在未提交更改:**
- 请用户先暂存或提交
- 或者直接创建分支并警告会携带现有更改3. Create and Switch to Branch
3. 创建并切换到分支
bash
undefinedbash
undefinedCreate new branch from current HEAD
从当前HEAD创建新分支
git checkout -b "$branch_name"
undefinedgit checkout -b "$branch_name"
undefined4. Verify Branch Created
4. 验证分支已创建
bash
undefinedbash
undefinedConfirm current branch
确认当前分支
git branch --show-current
**Expected:** Should output the new branch name.git branch --show-current
**预期结果:** 应输出新分支名称。5. Report Ready
5. 报告准备就绪
Temporary branch created: $branch_name
Ready to implement: $TASK临时分支已创建:$branch_name
可开始实现:$TASKQuick Reference
快速参考
| Situation | Action |
|---|---|
| Clean working directory | Create branch directly |
| Uncommitted changes | Stash/commit first OR warn and proceed |
| Branch exists | Append timestamp or ask for different name |
| 场景 | 操作 |
|---|---|
| 工作目录干净 | 直接创建分支 |
| 存在未提交更改 | 先暂存/提交 或 警告后继续 |
| 分支已存在 | 添加时间戳或询问其他名称 |
Common Mistakes
常见错误
Skipping clean directory check
跳过工作目录检查
- Problem: Carries over unrelated changes to new branch
- Fix: Always check first
git status --porcelain
- 问题: 将无关更改带入新分支
- 解决方法: 始终先检查
git status --porcelain
Not verifying branch creation
未验证分支创建
- Problem: May still be on wrong branch
- Fix: Always confirm with
git branch --show-current
- 问题: 可能仍处于错误分支
- 解决方法: 始终用确认
git branch --show-current
Example Workflow
示例工作流
You: I'm using the using-git-worktrees skill to create a temporary branch.
[Check git status - clean]
[Create branch: git checkout -b feature/subscription-user-id-uuid]
[Verify: git branch --show-current outputs "feature/subscription-user-id-uuid"]
Temporary branch created: feature/subscription-user-id-uuid
Ready to implement: Fix SubscriptionPlan user_id from int to UUID你:我正在使用using-git-worktrees技能创建临时分支。
[检查git状态 - 干净]
[创建分支:git checkout -b feature/subscription-user-id-uuid]
[验证:git branch --show-current输出"feature/subscription-user-id-uuid"]
临时分支已创建:feature/subscription-user-id-uuid
可开始实现:修复SubscriptionPlan的user_id从int改为UUIDRed Flags
注意事项
Never:
- Skip working directory check
- Proceed without verifying branch was created
- Create branch with uncommitted changes without warning
Always:
- Verify clean working directory first
- Confirm branch creation
- Use descriptive branch names
绝对不要:
- 跳过工作目录检查
- 未验证分支创建就继续
- 在未警告的情况下带未提交更改创建分支
始终要:
- 先验证工作目录是否干净
- 确认分支已创建
- 使用描述性分支名称
Integration
集成
Called by:
- brainstorming (Phase 4) - REQUIRED when design is approved and implementation follows
- subagent-driven-development - REQUIRED before executing any tasks
- executing-plans - REQUIRED before executing any tasks
- Any skill needing isolated workspace
Pairs with:
- finishing-a-development-branch - REQUIRED for cleanup after work complete
被以下技能调用:
- brainstorming(第4阶段)——设计获批后进入实现阶段时必须调用
- subagent-driven-development——执行任何任务前必须调用
- executing-plans——执行任何任务前必须调用
- 任何需要隔离工作区的技能
搭配使用:
- finishing-a-development-branch——工作完成后清理时必须调用