git-worktree
Create, list, inspect, and remove git worktrees in an isolated sibling directory so each agent session works in its own repo context. Use when the user wants to "create a worktree", "spin up a worktree", "work on a PR in isolation", "check out PR#N in a worktree", "list/clean up worktrees", "parallel branch workspace", or "isolated workspace for a feature". Triggers on "worktree", "git worktree", "isolated checkout", "sibling workspace", "parallel feature branch". Do NOT use for general push/merge/fetch/PR-lifecycle git work (use the `git` skill), for plain branch creation without a separate directory, or for a single simple commit (use `commit`).
- License 许可
- MIT
- 最近更新
- 2026-11-09
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- git-worktree
- description
- Create, list, inspect, and remove git worktrees in an isolated sibling directory so each agent session works in its own repo context. Use when the user wants to "create a worktree", "spin up a worktree", "work on a PR in isolation", "check out PR#N in a worktree", "list/clean up worktrees", "parallel branch workspace", or "isolated workspace for a feature". Triggers on "worktree", "git worktree", "isolated checkout", "sibling workspace", "parallel feature branch". Do NOT use for general push/merge/fetch/PR-lifecycle git work (use the `git` skill), for plain branch creation without a separate directory, or for a single simple commit (use `commit`).
02 资源文件 1
- 脚本scripts/worktree.sh8.0 KB
03 SKILL.md 正文
Git Worktree
When to Use (and When NOT to Use)
Use when:
- You want a feature branch to live in its own directory so the current workspace stays untouched (parallel agent sessions, long-running experiments).
- You need to check out a PR's branch in isolation to test or build on it.
- You want to list, inspect (branch / changes / ahead-behind / PR), or clean up existing worktrees.
Do NOT use when:
- The operation is push, merge, fetch, or PR lifecycle — use the
gitskill. - You just need a new branch in the same directory —
git checkout -bis enough. - You are committing staged changes — use
commit.
Input
- A git repository (the script resolves the toplevel itself).
- For
create: a name, branch ref, or PR reference. Optional explicit branch and base branch. - For
create/statusfrom a PR:ghauthenticated for the repo (optional — falls back gracefully).
Workflow
All actions are driven by the bundled script, which enforces the sibling-directory layout and YYYYMMDD_<kebab-case> naming. Pass the user's arguments straight through:
${CLAUDE_PLUGIN_ROOT}/skills/git-worktree/scripts/worktree.sh <action> [name] [branch] [base-branch]
- Parse intent into an action. Map the request to one of
create,list,status,remove. If ambiguous, ask which. - Run the script with the parsed arguments. It handles base-branch auto-detection (
origin/HEAD), PR-ref lookup viagh, branch-prefix stripping for clean directory names, and existing-branch reuse (remote → local → new). - For
remove, confirm the target first when the user gave a partial or fuzzy name — the script force-removes and prunes, which is hard to undo. It refuses ambiguous fuzzy matches and warns about uncommitted changes before removing, but still showlistoutput and confirm before running. - Report the resulting path and branch. After
create, tell the user tocdinto the printed path to start working.
Input parsing the script applies on create:
PR#42/#42→ resolves the PR's head viagh, fetchespull/42/headinto a local branch (works for fork PRs too), dir becomesYYYYMMDD_<branch-without-prefix>.feat/foo(orfix/,chore/,hotfix/,release/) → uses it as the branch, strips the prefix for the dir name.- Plain text → kebab-cased as both dir slug and (by default) branch name.
Output
- A worktree directory under
../<repo>_worktrees/(oncreate), or a removed/listed/inspected worktree. - Plain-text status to stdout; exit
0on success,1on failure. - No commits, no pushes — worktrees share the repo's
.git, so all branches are visible across them.
Outcomes we are looking for
- Each agent session is isolated. Concurrent work happens in separate directories with no checkout thrash on the main workspace.
- Worktree names are predictable. Every directory is
YYYYMMDD_<kebab-case>, so listings sort chronologically and never collide with the repo itself.
Recommended tools and practices (as of 2026-06-08)
For: each agent session is isolated
- Keep worktrees as siblings, never nested inside the repo. The script enforces
../<repo>_worktrees/; a worktree inside the repo confuses tooling and git status. - One worktree per concurrent task. Pairs with parallel-agent dispatch — each agent gets its own directory and branch.
For: predictable, low-friction cleanup
- Remove worktrees when the branch merges. Use
remove, then verify withlist; the script prunes stale metadata automatically. - Use
statusbefore cleanup to spot uncommitted changes or unmerged commits in a worktree you are about to delete.
References
scripts/worktree.sh: the executable that performs all four actions. Self-contained; safe to run directly.- The
gitskill (same plugin) covers push / merge / fetch / PR lifecycle and cross-references this skill for worktree work.
04 同仓库更多 Skills
testing-expert
Expert knowledge for analyzing testing architecture and planning improvements
security-hardening
Audit and harden repository security — supply chain, CI/CD scanners, secrets, credentials
review
Review implementation against project plan and verify completeness
qa-setup
Verify or create standardized QA commands for polyglot projects
prioritize
Prioritize review comments by severity
pre-commit-qa
Run standardized QA checks before committing changes