agentleFS
REPOZYREPOZY/superpowers-optimized/skills/using-git-worktrees/SKILL.md

using-git-worktrees

Skill146 starsChanged 7 months agoMITView on GitHub

Use before implementation when work should be isolated from the current branch. Triggers on: "use a worktree", "isolate this work", "don't touch main", experimental or risky changes that need isolation.

  • Installs packages

189 other projects use a version of this, 81 of them edited.

Adopted by

Most recently taken up by

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.
  • Leodorareluctant259Skill

    chinese-code-review

    中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈

    Also in 8 projects that use this

  • Leodorareluctant259Skill

    chinese-commit-conventions

    中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化

    Also in 8 projects that use this

  • obraSkill

    diagnosing-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

  • frankxaiSkill

    defense-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

  • xfstudioSkill

    test-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

  • kntismSkill

    condition-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

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 5 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 182 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Create an isolated branch workspace with safe defaults.

    line 11
  2. Very specific:

    If .worktrees/ exists — use it.

    line 26
  3. Very specific:

    If worktrees/ exists — use it.

    line 27
  4. Distinctive:

    Check project guidance file (e.g.

    line 28
  5. Very specific:

    Add the appropriate line to .gitignore.

    line 43
  6. Very specific:

    Commit the .gitignore change immediately: before proceeding — an uncommitted ignore entry is easy to lose and leaves the worktree …

    line 44
  7. Distinctive:

    If none of these files exist, skip dependency installation and note it in the output.

    line 83
  8. Distinctive:

    Run the project-appropriate test command to confirm the worktree starts clean:

    line 87
  9. Distinctive:

    If baseline tests fail, report the failures and ask whether to continue or investigate before proceeding.

    line 99

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Using Git Worktrees

Create an isolated branch workspace with safe defaults.

Required Start

Announce: I'm using the using-git-worktrees skill to set up an isolated workspace.

Directory Selection Priority

Check in order:

ls -d .worktrees 2>/dev/null     # Preferred (hidden)
ls -d worktrees 2>/dev/null      # Alternative
  1. If .worktrees/ exists — use it. If both exist, .worktrees/ wins.
  2. If worktrees/ exists — use it.
  3. Check project guidance file (e.g. CLAUDE.md) for a stated preference:
    grep -i "worktree.*director" CLAUDE.md 2>/dev/null
  4. Ask user.

Safety Check

For project-local worktree directories, verify ignore rules before creating:

git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null

If not ignored:

  1. Add the appropriate line to .gitignore.
  2. Commit the .gitignore change immediately before proceeding — an uncommitted ignore entry is easy to lose and leaves the worktree contents exposed to accidental staging.

Creation Steps

1. Detect project root and branch name

project=$(basename "$(git rev-parse --show-toplevel)")

Choose a descriptive BRANCH_NAME for the feature being isolated.

2. Create worktree and branch

git worktree add <path> -b <BRANCH_NAME>

Critical: The cd <path> in this step does not persist across separate shell calls. Use the full worktree path — cd <path> && <command> — in every subsequent Bash call rather than assuming the working directory carried over.

3. Run project setup

Auto-detect the project ecosystem and run the appropriate setup:

# Node.js
if [ -f package.json ]; then npm install; fi

# Rust
if [ -f Cargo.toml ]; then cargo build; fi

# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi

# Go
if [ -f go.mod ]; then go mod download; fi

If none of these files exist, skip dependency installation and note it in the output.

4. Run baseline tests

Run the project-appropriate test command to confirm the worktree starts clean:

# Use whichever applies
npm test
cargo test
pytest
go test ./...

Failure Handling

If baseline tests fail, report the failures and ask whether to continue or investigate before proceeding.

Success Output

Report:

  • Worktree path (full absolute path)
  • Branch name
  • Ecosystem detected and setup command(s) run
  • Baseline test status (passing count or failure summary)

Integration

Use with:

  • writing-plans
  • subagent-driven-development — REQUIRED before executing any tasks
  • executing-plans — REQUIRED before executing any tasks

Cleanup is handled by finishing-a-development-branch.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.