一键导入
using-git-worktrees
Use when feature work needs workspace isolation, branch-safe edits, or a written plan should not run in the current checkout.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when feature work needs workspace isolation, branch-safe edits, or a written plan should not run in the current checkout.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | using-git-worktrees |
| description | Use when feature work needs workspace isolation, branch-safe edits, or a written plan should not run in the current checkout. |
Create isolation only when it reduces risk. Detect existing isolation first.
Purpose: protect the user's current checkout from branch-scale work. Consumer: agents starting substantial feature work, plan execution, or risky multi-file edits. Failure consequence: work pollutes the user's active branch, or nested worktrees create phantom state. Falsifier: current workspace is already isolated, or the user explicitly wants the current checkout edited.
Use a worktree when:
Skip when:
git rev-parse --show-superproject-working-tree 2>/dev/null
GIT_DIR=$(cd "$(git rev-parse --git-dir)" && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" && pwd -P)
git branch --show-current
If GIT_DIR != GIT_COMMON and not a submodule, you are already isolated.
Prefer platform-native worktree tools when available.
Git fallback:
.worktrees/ or worktrees/; .worktrees/ wins..worktrees/.git check-ignore -q .worktrees || git check-ignore -q worktrees
git worktree add "$path" -b "$branch"
If ignore check fails, add the directory to .gitignore and commit that change
before creating project-local worktrees.
Do not use git stash as durable storage. Stash is only a same-turn parking
lot. If work must survive interruption, make a branch or WIP commit. If a stash
is unavoidable, anchor it before ending the turn:
git branch "wip/stash-<n>-<topic>" "stash@{<n>}"
Never use git stash pop; use git stash apply, verify the result, then drop
manually. Failure consequence: hidden stash entries expire, get overwritten, or
are forgotten during branch cleanup. Falsifier: every stash is reachable from a
named branch and the final report lists the branch or exact dirty files.
Use lifecycle prefixes for non-main branches:
work/<topic> active implementationwip/<topic> interrupted workreview/<topic> ready for reviewarchive/<date>-<topic> retained inactive workMerged local branches are cleanup candidates, not durable storage. Delete them
after confirmation with git branch -d <branch>, or rename retained evidence
under archive/<date>-<topic>.
Before ending a turn with dirty or unmerged work, report one of: committed branch, active worktree path and branch, anchored stash branch, or exact dirty files intentionally left uncommitted.
After entering the workspace, run setup and the narrow baseline command for the repo. If baseline fails, report the failure and ask before proceeding.
Use when a request needs product/design exploration, unclear requirements, multiple viable approaches, UI/UX choices, or new behavior whose intent is not yet bounded.
Use when 2+ independent tasks, failures, research lanes, exploration lanes, or path-scoped investigations can run without shared state, shared files, or sequential dependency.
Use when executing a written implementation plan inline in the current session with checkpoints and verification.
Use when adding or changing a capability surface such as a public function, API, command, prompt, workflow, schema/helper, policy, or reusable instruction.
Use when implementation is complete, verification passes, and the remaining decision is how to integrate, merge, PR, clean up, or finish the branch.
Use when creating or revising docs, plans, records, PR text, handoffs, or other prose that should be sparse, direct, and low-context.