← 教程列表
news

Step 1b: Git Worktree Fallback

📅 2026/6/12 16:30:02⏱ 约 5 分钟阅读👁 8 阅读

When no native tool is available, create a worktree manually. **Directory selection** (priority order): 1. Check for existing `.worktrees/` or `worktrees/` directory — if found, use it. If both exist, `.worktrees/` wins. 2. Check for existing `~/.config/superpowers/worktrees//` directory — if found, use it (backward compatibility with legacy global path). 3. Check the project's agent instruction file (CLAUDE.md, GEMINI.md, AGENTS.md, .cursorrules, or equivalent) for a worktree directory preference. 4. Default to `.worktrees/`. No interactive directory selection prompt. The global path (`~/.config/superpowers/worktrees/`) is no longer offered as a choice to new users, but existing worktrees at that location are detected and used for backward compatibility. **Safety verification** (project-local directories only): ```bash git check-ignore -q .worktrees 2>/dev/null ``` If not ignored, add to `.gitignore` and commit before proceeding. **Create:** ```bash git worktree add "$path" -b "$BRANCH_NAME" cd "$path" ``` **Hooks awareness:** Git worktrees do not inherit the parent repo's hooks directory. After creating a worktree via 1b, symlink the hooks directory from the main repo if one exists: ```bash if [ -d "$MAIN_ROOT/.git/hooks" ]; then ln -sf "$MAIN_ROOT/.git/hooks" "$path/.git/hooks" fi ``` This prevents pre-commit checks, linters, and other hooks from silently stopping when work moves to a worktree. (Idea from PR #965.) **Sandbox fallback:** If `git worktree add` fails with a permission error, treat as a restricted environment. Skip creation, work in current directory, proceed to Step 3. **Step numbering note:** The current skill has Steps 1-4 as a flat list. This redesign uses 0, 0.5, 1a, 1b, 3, 4. There is no Step 2 — it was the old monolithic "Create Isolated Workspace" which is now split into the 1a/1b structure. The implementation should renumber cleanly (e.g., 0 → "Step 0: Detect", 0.5 → within Step 0's flow, 1a/1b → "Step 1", 3 → "Step 2", 4 → "Step 3") or keep the current numbering with a note. Implementer's choice.

← 返回教程列表 AI8899 · 内容仅供学习参考