using-git-worktrees
Featured当需要开始与当前工作区隔离的功能开发,或在执行实现计划之前使用——通过原生工具或 git worktree 回退机制确保隔离工作区存在
Code & Development 7,264 stars
705 forks Updated 4 days ago MIT
Install
Quality Score: 99/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
Skill Content
# 使用 Git 工作树
## 概述
确保工作发生在隔离的工作区中。优先使用你的平台的原生 worktree 工具。仅在没有原生工具可用时,再回退到手动 git worktree。
**核心原则:** 先检测现有隔离。然后用原生工具。再回退到 git。绝不与 harness 对抗。
**开始时宣布:** "我正在使用 using-git-worktrees 技能来建立一个隔离的工作区。"
## 步骤 0:检测现有隔离
**创建任何东西之前,先检查你是否已经在一个隔离的工作区里。**
```bash
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
BRANCH=$(git branch --show-current)
```
**Submodule 守卫:** 在 git submodule 内 `GIT_DIR != GIT_COMMON` 也为真。在判定"已经在 worktree 内"之前,先确认你不在 submodule 里:
```bash
# 如果这条命令返回路径,说明你在 submodule 里,不是 worktree —— 按普通仓库处理
git rev-parse --show-superproject-working-tree 2>/dev/null
```
**如果 `GIT_DIR != GIT_COMMON`(且不是 submodule):** 你已经在一个 linked worktree 内。跳到步骤 2(项目设置)。**不要**再创建一个 worktree。
按分支状态报告:
- 在某个分支上:"已经在隔离工作区 `<path>`,分支 `<name>`。"
- 分离 HEAD:"已经在隔离工作区 `<path>`(分离 HEAD,由外部管理)。完成时需要创建分支。"
**如果 `GIT_DIR == GIT_COMMON`(或在 submodule 内):** 你在一个普通的仓库检出里。
用户是否已经在你的 instructions 里表明过 worktree 偏好?如果没有,创建 worktree 之前先征求同意:
> "你希望我搭一个隔离的 worktree 吗?它能保护你当前分支不被改动。"
如果用户已声明过偏好,直接遵循,不再询问。如果用户拒绝同意,原地工作并跳到步骤 2。
## 步骤 1:创建隔离工作区
**你有两种机制。按这个顺序尝试。**
### 1a. 原生 Worktree 工具(首选)
用户已经请求隔离工作区(步骤 0 已获同意)。你是否已经有创建 worktree 的方法?可能是名为 `EnterWorktree`、`WorktreeCreate` 的工具、`/worktree` 命令,或 `--worktree` 标志。如果有,用它,然后跳到步骤 2。
原生工具自动处理目录放置、分支创建和清理。在你已经有原生工具的情况下使用 `git worktree add`,会创建你的 harness 看不到也无法管理的"幻影状态"。
只有在没有原生 worktree 工具可用时,才进入步骤 1b。
### 1b. Git Worktree 回退
**只在步骤 1a 不适用时使用** —— 你没有可用的原生 worktree 工具。...
Details
- Author
- jnMetaCode
- Repository
- jnMetaCode/superpowers-zh
- Created
- 4 months ago
- Last Updated
- 4 days ago
- Language
- JavaScript
- License
- MIT
Bundled in these plugins
Similar Skills
Semantically similar based on skill content — not just same category
Code & Development Listed
using-git-worktrees
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
18 Updated 1 weeks ago
heymegabyte Code & Development Listed
using-git-worktrees
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
3 Updated today
Ralph-Workflow Code & Development Listed
using-git-worktrees
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
0 Updated 5 days ago
lhbsaa