Skip to content
jnmetacode avatar

Using Git Worktrees

Git-worktree workflow that detects existing isolation, prefers native tools, and falls back to manual git worktrees.

CCM score
68 of 100
skills.sh installs
996
GitHub stars
8.6K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers detecting an existing isolated workspace, creating one via a native worktree tool or git worktree add, project setup, and a clean-baseline test run
  • Includes a submodule guard (git rev-parse --show-superproject-working-tree) and a git check-ignore check that blocks committing worktree directories
  • Enforces native worktree tools before falling back to git, and reports a sandbox fallback to in-place work on permission errors
  • Designed for agent workflows that start feature implementation in a separate workspace from the current checkout

Install

$ npx -y skills add jnmetacode/superpowers-zh --skill using-git-worktrees -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

使用 Git 工作树

概述

确保工作发生在隔离的工作区中。优先使用你的平台的原生 worktree 工具。仅在没有原生工具可用时,再回退到手动 git worktree。

核心原则: 先检测现有隔离。然后用原生工具。再回退到 git。绝不与 harness 对抗。

开始时宣布: "我正在使用 using-git-worktrees 技能来建立一个隔离的工作区。"

步骤 0:检测现有隔离

创建任何东西之前,先检查你是否已经在一个隔离的工作区里。

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 里:

# 如果这条命令返回路径,说明你在 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 工具(首选)

Details

Repository
github.com/jnmetacode/superpowers-zh
Categories
Git & Releases, Agent Workflow & Planning
First seen
Jun 3, 2026

Questions

What does the using-git-worktrees skill do?

The using-git-worktrees skill makes sure work happens in an isolated workspace, separate from the current working tree. It first checks whether you are already in an isolated worktree, then uses the platform's native worktree tool or falls back to git worktree.

How do I install the using-git-worktrees skill?

Run npx -y skills add jnmetacode/superpowers-zh --skill using-git-worktrees -y in your project. After that, using-git-worktrees lets the agent set up an isolated worktree before it starts a feature or implementation plan.

Where does using-git-worktrees sit among Git & Releases skills?

Within Git & Releases, using-git-worktrees is listed alongside triage, git-guardrails-claude-code, setup-pre-commit, caveman-commit and pr. Its own focus is isolating feature work in a worktree and running project setup and a baseline test run there.

Does using-git-worktrees protect files from being committed by accident?

Yes, using-git-worktrees checks with git check-ignore that a project-local worktree directory such as .worktrees is ignored before it creates a worktree. If it is not ignored, the skill adds it to .gitignore and commits that change first.

More from jnmetacode/superpowers-zh

All 20

Similar to Using Git Worktrees

More Git & Releases