git-worktree
Git Worktree 管理命令。提供 init、list、remove 三个子命令来管理项目 worktree。
Best use case
git-worktree is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Git Worktree 管理命令。提供 init、list、remove 三个子命令来管理项目 worktree。
Teams using git-worktree should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/git-worktree/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How git-worktree Compares
| Feature / Agent | git-worktree | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Git Worktree 管理命令。提供 init、list、remove 三个子命令来管理项目 worktree。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Git Worktree 管理命令 (v1.0.0)
管理项目中的 Git worktree,支持创建、列表查看和删除操作。
## 调用方式
```
/git-worktree init "任务描述" # 创建 worktree
/git-worktree list # 列出所有 worktree
/git-worktree remove # 删除 worktree
```
## 命令详解
### init - 创建新的 Worktree
根据用户描述的任务,自动推断分支类型并创建 worktree。创建完成后询问用户是否要在 iTerm2 中打开新 tab 并启动 Claude。
**调用方式:**
```
/git-worktree init "任务描述"
```
**参数说明:**
- `任务描述` - 任务的简短描述(必需)
**交互流程:**
1. 执行脚本创建 worktree
2. 脚本输出 `[ASK_USER_OPEN_ITERM]` 标记和信息
3. AI 检测到标记后,使用 AskUserQuestion 询问用户是否打开 iTerm2
4. 用户同意后,执行以下命令打开 iTerm2:
```bash
cd /Users/lee0407/dev/projs/auth && python3 .claude/skills/git-worktree/scripts/open_iterm.py "<worktree_path>" "<branch_name>" "<description>"
```
**自动推断的分支类型:**
| 关键词 | 分支类型 |
|--------|----------|
| feat, 功能, 添加, 新增, 实现 | feature |
| fix, 修复, bug, 错误, 问题 | bugfix |
| refactor, 重构, 优化, 重写 | refactor |
| docs, 文档, 说明, readme | docs |
| test, 测试, 单元 | test |
| chore, 配置, 构建, 依赖 | chore |
**执行流程:**
1. 切换到 develop 分支并拉取最新代码
2. 根据描述推断分支类型并生成分支名
3. 创建新分支
4. 在 `worktrees/` 目录下创建 worktree
5. 切换回 develop 分支
6. 输出 `[ASK_USER_OPEN_ITERM]` 标记,等待 AI 询问用户
**使用示例:**
```
/git-worktree init "添加用户 Excel 导入导出功能"
# 结果:创建 feature/excel-import-export 分支和 worktree
# AI 检测到 [ASK_USER_OPEN_ITERM] 标记
# AI 使用 AskUserQuestion 询问用户
# 用户同意后执行 open_iterm.py 打开 iTerm2 并启动 Claude
```
## AI 响应规则
当执行 `/git-worktree init` 后,脚本会输出 `[ASK_USER_OPEN_ITERM]` 标记。AI 应:
1. **检测到 `[ASK_USER_OPEN_ITERM]` 标记**
2. **解析标记后的信息**(格式:`path|branch|description`)
3. **使用 AskUserQuestion 询问用户**:
```json
{
"questions": [
{
"question": "是否要在 iTerm2 中打开新 tab 并启动 Claude?",
"header": "iTerm2",
"options": [
{"label": "是,打开 iTerm2", "description": "在 iTerm2 新 tab 中启动 Claude"},
{"label": "否,稍后手动打开", "description": "不打开,稍后自行执行"}
],
"multiSelect": false
}
]
}
```
4. **用户选择"是"后**,执行:
```bash
cd /Users/lee0407/dev/projs/auth && python3 .claude/skills/git-worktree/scripts/open_iterm.py "<worktree_path>" "<branch_name>" "<description>"
```
## 脚本说明
### worktree_manager.py
主脚本,处理 worktree 的创建、列表和删除操作。
### open_iterm.py
辅助脚本,用于在 iTerm2 中打开新 tab 并启动 Claude。
## 命令详解
### list - 列出所有 Worktree
显示当前仓库中所有 worktree 的列表。
**调用方式:**
```
/git-worktree list
```
**输出格式:**
```
Git Worktree 列表
============================================================
主 /Users/lee0407/dev/projs/auth [develop] ✓
└─ worktrees/feature-excel-import [feature/excel-import] ✓
└─ worktrees/bugfix-login-issue [bugfix/login-issue] ✗
============================================================
✓ = 干净工作区 | ✗ = 有未提交更改
```
**使用示例:**
```
/git-worktree list
```
### remove - 删除 Worktree
交互式删除指定的 worktree。
**调用方式:**
```
/git-worktree remove # 交互式选择
/git-worktree remove 1 # 按索引删除
/git-worktree remove feature-xxx # 按路径删除
```
**注意事项:**
- 不会删除主目录的 worktree
- 不会删除有未提交更改的 worktree(除非强制)
**使用示例:**
```
/git-worktree remove
# 显示可删除的 worktree 列表,供用户选择
```
## 工作原理
Git Worktree 允许在同一个仓库中同时在多个分支上工作:
```
auth/
├── .git/
├── worktrees/
│ ├── feature-excel-import/ # 功能开发 worktree
│ └── bugfix-login-issue/ # Bug 修复 worktree
├── auth-biz/
├── auth-server/
└── ...
```
## 最佳实践
1. **每个任务一个 worktree** - 保持工作区干净
2. **及时清理** - 任务完成后删除不需要的 worktree
3. **描述清晰** - 使用有意义的任务描述便于识别
4. **先更新 develop** - 创建前确保 develop 是最新的
## 注意事项
1. 所有 worktree 必须创建在 `worktrees/` 目录下
2. 创建前会自动检查 develop 分支是否为最新
3. 删除前会询问用户确认
4. 不会删除主目录的 worktreeRelated Skills
worktree-setup
Automatically invoked after `git worktree add` to create data/shared symlink and data/local directory. Required before starting work in any new worktree.
worktree-tending
Manage git worktrees for parallel branch development using custom git scripts (git-newtree, git-killtree, git-maingulp). Use when creating new worktrees, listing active worktrees, or closing/merging worktrees back to main. All worktrees are stored in .tree/ subdirectories of the repository.
using-git-worktrees
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verifi...
agent-ops-git-worktree
Manage git worktrees for isolated development. Create, list, remove, and work in worktrees.
bgo
Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.
smartrecruiters-automation
Automate Smartrecruiters tasks via Rube MCP (Composio). Always search tools first for current schemas.
skills-creator
Creates new Claude Code skills in the .claude/skills/ directory. Specializes in designing well-structured, effective skills through thorough requirements gathering. Use when the user wants to create a new skill, command, agent, or automation.
skill_design
Alias router for the design phase skill in LocusQ. Use when user references `skill_design` explicitly or requests UI/interface design work.
skill-protocol-mastery
This skill should be used when the user asks to "create a skill", "write a SKILL.md", "validate skill structure", "improve skill description", "understand skill protocol", "design skill architecture", or needs guidance on progressive disclosure, trigger phrases, writing style, or skill validation for Claude Code.
skill-creator
Create new skills following a structured 4-phase workflow. Use when you need to build reusable agent skills with proper validation.
skill-builder-medical
Specialized guide for creating Claude Code skills for Dr. Sophia AI medical system. Includes healthcare integration patterns (FHIR/REST/EHR), medical compliance validation (HIPAA/PBS/TGA), botanical design integration, Railway deployment patterns, and proven examples from our 7 production skills. Use when creating skills specifically for Dr. Sophia AI, medical integration skills, healthcare compliance skills, EHR workflows, or adapting our proven skill patterns.
Skill Builder / Creator
Create high-quality skills with modular structure, progressive disclosure, and token-efficient design.