using-git-worktrees
Skill4 starsChanged 6 days agoMITView on GitHub
Use when the user asks for an isolated workspace or git worktree for a change, or wants
- Installs packages
189 other projects use a version of this, 159 of them edited.
Adopted by
Most recently taken up by
- DemonDamon/AgenticXedited, first seen Nov 9, 2026
- roundpilot/superpowers-antigravityedited, first seen Nov 8, 2026
- REPOZY/superpowers-optimizededited, first seen Nov 8, 2026
- lingyired/status-trioedited, first seen Nov 8, 2026
- afawfawffaf/my-skillsedited, first seen Nov 8, 2026
- supermorkat/qawa-arenaedited, first seen Nov 8, 2026
Used with
Projects with it also use chinese-code-review, chinese-commit-conventions and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
Leodorareluctant259Skillchinese-code-review
中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈
Also in 8 projects that use this
Leodorareluctant259Skillchinese-commit-conventions
中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化
Also in 8 projects that use this
obraSkilldiagnosing-superpowers
Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.
Also in 20 projects that use this
frankxaiSkilldefense-in-depth
Use when invalid data causes failures deep in execution, requiring validation at multiple system layers - validates at every layer data passes through to make bugs structurally impossible
Also in 4 projects that use this
xfstudioSkilltest-fixing
Run tests and systematically fix all failing tests using smart error grouping. Use when user asks to fix failing tests, mentions test failures, runs test suite and failures occur, or requests to make tests pass.
Also in 3 projects that use this
kntismSkillcondition-based-waiting
Use when tests have race conditions, timing dependencies, or inconsistent pass/fail behavior - replaces arbitrary timeouts with condition polling to wait for actual state changes, eliminating flaky tests from timing guesses
Also in 3 projects that use this
- +3 more from Leodorareluctant259
Other versions189 projects use a version of this.
Word for word · 0
None found.
Edited · 159
- obra/superpowers★ 314k91% same
- jnMetaCode/superpowers-zh★ 8.4k16% same
- openai/plugins★ 7.8k91% same
- farm-fe/farm★ 5.6k64% same
- lingyired/status-trio★ 1.8k91% same
- pcvelz/superpowers★ 1.3k82% same
- DemonDamon/AgenticX★ 1k20% same
- usewhale/DeepSeek-Code-Whale★ 93364% same
- usewhale/Whale★ 92864% same
- coco-research/coco★ 79720% same
149 more not listed
Wrote their own version · 30
- microsoft/FluidFramework★ 4.9ksame name
- silvertakana/worldwideview★ 1.9ksame name
- GanyuanRan/Aegis★ 1.4ksame name
- Innei/ryugi★ 378same name
- KbWen/agentic-os★ 229same name
- aaddrick/claude-pipeline★ 128same name
- KbWen/agent-virtual-office★ 65same name
- drvoss/everything-copilot-cli★ 48same name
- felvieira/claude-skills-fv★ 27same name
- RBraga01/a-team★ 24same name
20 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository28 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/vercel-composition-patterns/AGENTS.mdAGENTS.md
- skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- agent-browserSkill
- break-uiSkill
- claude-skill-creatorSkill
- codebase-designSkill
- code-simplificationSkill
- design-taste-frontendSkill
- domain-modelingSkill
- finishing-a-development-branchSkill
- frontend-designSkill
- grillingSkill
- handoffSkill
- improve-codebase-architectureSkill
- performance-optimizationSkill
- ponytailSkill
- prompt-refinerSkill
- readme-syncSkill
- review-reportSkill
- security-best-practicesSkill
- supabase-postgres-best-practicesSkill
- systematic-debuggingSkill
- test-driven-developmentSkill
- triageSkill
- vercel-composition-patternsSkill
- vercel-react-best-practicesSkill
- writing-for-agentsSkill
The file
We split this skill into the rules it gives an agent
8 rules. 1 is common, 5 are distinctive, and 2 are very specific to this project.
1
Common
Most of the 182 edited versions we read keep these.
5
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Ensure work happens in an isolated workspace.
- Distinctive: line 70
Only proceed to Step 1b if you have no native worktree tool available.
- Distinctive: line 78
Follow this priority order.
- Very specific: line 87
If found, use it. If both exist, .worktrees wins.
- Very specific: line 99
If NOT ignored: Add the directory to .git/info/exclude, which ignores it locally without a commit, then proceed.
- Distinctive: line 113
Sandbox fallback: If git worktree add fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation …
- Distinctive: line 117
Use the project's documented setup first.
- Common: line 137
Run tests to ensure workspace starts clean:
“Common” is measured: kept by at least 6 in 10 of the 182 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Scope and integration
Apply this skill to the requested target and task. User instructions and project conventions take precedence; loading it does not authorize commits, pushes, publishing, or unrelated changes. A request for a worktree or isolated workspace is the consent asked for in Step 0. Use the project's documented setup and required checks (README, AGENTS.md, CLAUDE.md, Makefile) before the generic commands in Steps 2 and 3.
Using Git Worktrees
Overview
Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.
Core principle: Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.
Step 0: Detect Existing Isolation
Before creating anything, check if you are already in an isolated workspace.
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 guard: GIT_DIR != GIT_COMMON is also true inside git submodules. Before concluding "already in a worktree," verify you are not in a submodule:
# If this returns a path, you're in a submodule, not a worktree — treat as normal repo
git rev-parse --show-superproject-working-tree 2>/dev/nullIf GIT_DIR != GIT_COMMON (and not a submodule): You are already in a linked worktree. Skip to Step 2 (Project Setup). Do NOT create another worktree.
Report with branch state:
- On a branch: "Already in isolated workspace at
<path>on branch<name>." - Detached HEAD: "Already in isolated workspace at
<path>(detached HEAD, externally managed). Branch creation needed at finish time."
If GIT_DIR == GIT_COMMON (or in a submodule): You are in a normal repo checkout.
Has the user already indicated their worktree preference in your instructions? If not, ask for consent before creating a worktree:
"Would you like me to set up an isolated worktree? It protects your current branch from changes."
Honor any existing declared preference without asking. If the user declines consent, work in place and skip to Step 2.
Step 1: Create Isolated Workspace
You have two mechanisms. Try them in this order.
1a. Native Worktree Tools (preferred)
The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like EnterWorktree, WorktreeCreate, a /worktree command, or a --worktree flag. If you do, use it and skip to Step 2.
Native tools handle directory placement, branch creation, and cleanup automatically. Using git worktree add when you have a native tool creates phantom state your harness can't see or manage.
Only proceed to Step 1b if you have no native worktree tool available.
1b. Git Worktree Fallback
Only use this if Step 1a does not apply — you have no native worktree tool available. Create a worktree manually using git.
Directory Selection
Follow this priority order. Explicit user preference always beats observed filesystem state.
- Check your instructions for a declared worktree directory preference. If the user has already specified one, use it without asking.
- Check for an existing project-local worktree directory:
If found, use it. If both exist,ls -d .worktrees 2>/dev/null # Preferred (hidden) ls -d worktrees 2>/dev/null # Alternative.worktreeswins. - If there is no other guidance available, default to
.worktrees/at the project root.
Safety Verification (project-local directories only)
MUST verify directory is ignored before creating worktree:
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/nullIf NOT ignored: Add the directory to .git/info/exclude, which ignores it locally without a commit, then proceed. Add it to .gitignore instead only if the user wants the ignore rule shared, and commit that change only when asked.
Why critical: Prevents accidentally committing worktree contents to repository.
Create the Worktree
# Determine path based on chosen location
path="$LOCATION/$BRANCH_NAME"
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"Sandbox fallback: If git worktree add fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.
Step 2: Project Setup
Use the project's documented setup first. Without one, auto-detect and run appropriate setup:
# Node.js
if [ -f package.json ]; then npm install; fi
# Rust
if [ -f Cargo.toml ]; then cargo build; fi
# Go
if [ -f go.mod ]; then go mod download; fiFor Python, install only into the project's virtual environment with its own
tool (for example uv sync, poetry install, or pip install -r
requirements.txt inside an activated venv). Ask before installing into a global
or system interpreter.
Step 3: Verify Clean Baseline
Run tests to ensure workspace starts clean:
# Use project-appropriate command
npm test / cargo test / pytest / go test ./...If tests fail: Report failures, ask whether to proceed or investigate.
If tests pass: Report ready.
Report
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>Quick Reference
| Situation | Action |
| Already in linked worktree | Skip creation (Step 0) |
| In a submodule | Treat as normal repo (Step 0 guard) |
| Native worktree tool available | Use it (Step 1a) |
| No native tool | Git worktree fallback (Step 1b) |
.worktrees/ exists | Use it (verify ignored) |
worktrees/ exists | Use it (verify ignored) |
| Both exist | Use .worktrees/ |
| Neither exists | Check instruction file, then default .worktrees/ |
| Directory not ignored | Add to .git/info/exclude (no commit) |
| Permission error on create | Sandbox fallback, work in place |
| Tests fail during baseline | Report failures + ask |
| No package.json/Cargo.toml | Skip dependency install |
Common Rationalizations
| Excuse | Reality |
| "I'm obviously not in a worktree — no need to check" | Run Step 0. Harness-created isolation and submodules both fool eyeballing; the detection commands settle it. |
"git worktree add is quicker than hunting for a native tool" | A native tool (e.g. EnterWorktree) owns placement, branching, and cleanup. Bypassing it is the #1 mistake — it creates phantom state your harness can't see or manage. |
| "The worktree directory is surely ignored already" | Run git check-ignore. An unignored worktree directory commits the whole tree into the repo. |
| "Any directory name works" | Explicit instructions beat an existing project-local directory, which beats the .worktrees/ default. |
| "The workspace is fresh — baseline tests can wait" | A dirty baseline makes every later failure ambiguous. Run the tests now; proceeding past failures is your human partner's call. |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

