agentleFS
axiomanticaxiomantic/spellbook/skills/using-git-worktrees/SKILL.md

using-git-worktrees

Skill10 starsChanged 3 months agoMITView on GitHub

Use when starting feature work that needs isolation from current workspace, or setting up parallel development tracks. Triggers: 'worktree', 'separate branch', 'isolate this work', 'don't mess up current work', 'work on two things at once', 'parallel workstreams', 'new branch for this', 'keep my current work safe'.

  • Installs packages

139 other projects use a version of this, 107 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use diagnosing-superpowers, chinese-git-workflow and 9 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.
  • 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 6 projects that use this

  • MorningStar0709Skill

    chinese-git-workflow

    Configure Git for domestic platforms and manage branching strategies suitable for Chinese teams. Use when the user asks to configure remotes, set up SSH, or manage Git workflows for Gitee, Coding, Jihu GitLab, or CNB, including requests like "配置国内 Git", "设置 Gitee 远程仓库", "推荐适合小团队的 Git 流程".

    Also in 4 projects that use this

  • shibit-netSkill

    chinese-code-review

    中文 review 沟通参考——话术模板、分级标注(必须修复/建议修改/仅供参考)、国内团队常见反模式应对。仅在用户显式 /chinese-code-review 时调用,不要根据上下文自动触发。

    Also in 3 projects that use this

  • shibit-netSkill

    chinese-commit-conventions

    中文 commit 与 changelog 配置参考——Conventional Commits 中文适配、commitlint/husky/commitizen 中文模板、conventional-changelog 中文配置。仅在用户显式 /chinese-commit-conventions 时调用,不要根据上下文自动触发。

    Also in 3 projects that use this

  • MorningStar0709Skill

    workflow-runner

    Run an agency-orchestrator style YAML workflow inside the current Trae conversation by simulating or coordinating multiple roles. Use when the user provides a `.yaml` or `.yml` workflow, asks for multi-role collaboration, says things like “用多个角色一起评审这个 PRD”“多角色协作”“先生成工作流再执行”“让产品经理、架构师、QA 一起看一下”, or wants roles such as product manager, architect, reviewer, or QA to work together. Supports layered execution, role prompting, variable interpolation, document-backed inputs, and parallel steps only when the current environment has a clear subagent mapping. Do not use for ordinary implementation plans, simple code changes, or tasks already covered by `writing-plans`, `executing-plans`, `subagent-driven-development`, or single-purpose review/debug skills.

    Also in 4 projects that use this

  • MicrosoftSkill

    testing-anti-patterns

    Use when writing or changing tests, adding mocks, or tempted to add test-only methods to production code - prevents testing mock behavior, production pollution with test-only methods, and mocking without understanding dependencies

    Also in 3 projects that use this

  • +1 more from shibit-net

The file

Show its rules and text

We split this skill into the rules it gives an agent

14 rules. 1 is common, 11 are distinctive, and 2 are very specific to this project.

  • 1

    Common

    Most of the 132 edited versions we read keep these.

  • 11

    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
  1. Distinctive:

    When multiple repos share a branch name or belong to the same feature, they nest under the same workspace directory.

    line 52
  2. Distinctive:

    Follow this priority order:

    line 70
  3. Distinctive:

    If override found: Use it without asking.

    line 77
  4. Very specific:

    If found: Use ~/Development/worktrees/{workspace-name}/{project}.

    line 85
  5. Very specific:

    Default: ~/Development/worktrees/{branch-slug}/{project}.

    line 93
  6. Distinctive:

    If NOT ignored: add to .gitignore + commit immediately.

    line 118
  7. Distinctive:

    Add appropriate line to .gitignore

    line 122
  8. Common:

    Run tests to ensure worktree starts clean:

    line 169
  9. Distinctive:

    Do tests pass in new worktree?

    line 179
  10. Distinctive:

    IF NO to any: Report failure, do NOT proceed with implementation.

    line 180
  11. Distinctive:

    Check context for autonomous mode indicators:

    line 197
  12. Distinctive:

    When autonomous mode is active:

    line 201
  13. Distinctive:

    All tests failing (baseline completely broken)

    line 213
  14. Distinctive:

    Before reporting worktree ready -- if ANY unchecked, STOP and resolve:

    line 266

“Common” is measured: kept by at least 6 in 10 of the 132 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

<ROLE> Build Engineer specializing in workspace isolation. Your reputation depends on clean, reproducible development environments that never corrupt the main workspace. Improper worktree setup causes repository corruption and lost work. This is very important. </ROLE>

Announce: "Using git-worktrees skill for isolated workspace."

Invariant Principles

  1. Directory precedence: CLAUDE.md/AGENTS.md override > existing ~/Development/worktrees/ > default (never assume)
  2. Safety gate: Project-local worktrees MUST be gitignored before creation
  3. Clean baseline: Tests must pass before implementation begins (interactive default; autonomous mode applies graduated policy -- see Autonomous Mode)
  4. Auto-detect over hardcode: Infer setup from manifest files

Inputs

InputRequiredDescription
feature_nameYesName for the worktree branch (e.g., "add-dark-mode")
base_branchNoBranch to base worktree on (defaults to current HEAD)
worktree_preferenceNoExplicit path preference from CLAUDE.md or user

Outputs

OutputTypeDescription
worktree_pathPathAbsolute path to created worktree directory
branch_nameStringName of the created branch
baseline_statusReportTest results confirming clean starting state

Workspace Structure

Worktrees are organized by workspace (branch or feature name), not by project:

~/Development/worktrees/
  {workspace-name}/
    {repo-a}/          <- git worktree
    {repo-b}/          <- git worktree

When multiple repos share a branch name or belong to the same feature, they nest under the same workspace directory. This makes it easy to find all repos related to a single effort.

Examples:

~/Development/worktrees/mcp-events/fastmcp/         # shared branch across repos
~/Development/worktrees/mcp-events/python-sdk/
~/Development/worktrees/mcp-events/typescript-sdk/
~/Development/worktrees/fix-auth-flow/myproject/     # single-repo feature

Project CLAUDE.md or AGENTS.md may specify a different naming convention for the workspace name (e.g., ODY-2863-card-reader-eligibility for ticket-grouped tools). The nesting structure remains the same: {workspace}/{repo}/.

Directory Selection Process

Follow this priority order:

1. Check CLAUDE.md / AGENTS.md for Project Override

Some projects override the default worktree location (e.g., ticket-grouped workspace tools). Check for explicit worktree path instructions.

If override found: Use it without asking.

2. Check Existing Global Directory

ls -d ~/Development/worktrees/ 2>/dev/null

If found: Use ~/Development/worktrees/{workspace-name}/{project}.

3. Default to Global Location

mkdir -p ~/Development/worktrees/

Default: ~/Development/worktrees/{branch-slug}/{project}. No gitignore needed (outside project).

Safety Verification

The default location (~/Development/worktrees/) is outside the project, so no gitignore verification is needed. If a project override directs worktrees to a project-local path, the following gate applies:

<CRITICAL> Worktree contents committed to the repository causes permanent pollution. This gate is non-negotiable: verify gitignore status before creating any project-local worktree. </CRITICAL>

For Project-Local Directories (only when override specifies one)

MUST verify directory is ignored before creating worktree:

git check-ignore -q "$WORKTREE_DIR" 2>/dev/null
<analysis> Before creating worktree: - Does target directory already exist? - Is directory preference established (override > default)? - Is project-local path gitignored? If NOT ignored: add to .gitignore + commit immediately. Worktree contents must never be tracked. </analysis>

If NOT ignored:

  1. Add appropriate line to .gitignore
  2. Commit the change
  3. Proceed with worktree creation

For Global Directory (~/Development/worktrees/ -- the default)

No .gitignore verification needed -- outside project entirely.

Creation Steps

1. Detect Project Name

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

2. Create Worktree

# Default path (override may change this)
path="$HOME/Development/worktrees/$BRANCH_NAME/$project"
mkdir -p "$(dirname "$path")"

# Check if branch/worktree already exists
git worktree list | grep -q "$BRANCH_NAME" && echo "ERROR: Worktree exists"

# Create worktree with new branch
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"

3. Run Project Setup

Auto-detect and run appropriate setup:

if [ -f package.json ]; then npm install; fi
if [ -f Cargo.toml ]; then cargo build; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install || uv sync; fi
if [ -f go.mod ]; then go mod download; fi

If setup fails: Report specific failure. Ask whether to proceed or troubleshoot.

4. Verify Clean Baseline

Run tests to ensure worktree starts clean:

# Use project-appropriate command: npm test / cargo test / pytest / go test ./...
<reflection> After worktree creation: - Did `git worktree add` succeed? - Are dependencies installed? - Do tests pass in new worktree? IF NO to any: Report failure, do NOT proceed with implementation. </reflection>

If tests fail: Report failures, ask whether to proceed or investigate.

If tests pass: Report ready.

5. Report Location

Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>

Autonomous Mode Behavior

Check context for autonomous mode indicators:

  • "Mode: AUTONOMOUS" or "autonomous mode"
  • worktree preference specified (e.g., "single", "per_parallel_track", "none")

When autonomous mode is active:

Skip These Interactions

  • "Where should I create worktrees?" -- use ~/Development/worktrees/{branch}/{project} or CLAUDE.md override
  • "Tests fail during baseline -- ask whether to proceed" -- proceed if minor, pause if critical

Make These Decisions Autonomously

  • Directory location: Use ~/Development/worktrees/{branch}/{project} as default if no CLAUDE.md override
  • Gitignore fix: Always fix automatically (add to .gitignore + commit)
  • Minor test failures: Log and proceed; major failures pause

Circuit Breakers (Always Pause For)

  • All tests failing (baseline completely broken)
  • Git worktree command fails (structural git issue)
  • .gitignore cannot be modified (permissions or other issue)

Quick Reference

SituationAction
CLAUDE.md/AGENTS.md overrideUse specified path
No overrideUse ~/Development/worktrees/{branch-slug}/{project}
Override points to project-local pathVerify gitignored first
Directory not ignoredAdd to .gitignore + commit
Tests fail during baselineReport failures + ask
Worktree already existsReport error, ask for new name
Setup command failsReport failure, ask how to proceed
No package.json/Cargo.tomlSkip dependency install

Common Mistakes

MistakeProblemFix
Skip ignore verificationWorktree contents get tracked, pollute git statusAlways git check-ignore before creating project-local worktree
Assume directory locationCreates inconsistency, violates project conventionsFollow priority: override > default
Proceed with failing testsCan't distinguish new bugs from pre-existing issuesReport failures, get explicit permission to proceed
Hardcode setup commandsBreaks on projects using different toolsAuto-detect from manifest files
Put worktrees under project nameMulti-repo features get scatteredGroup by workspace (branch/feature), nest repos inside

Example Workflow

[Check CLAUDE.md -- no override]
[Default to ~/Development/worktrees/feature-auth/myproject]
[Create worktree: git worktree add ~/Development/worktrees/feature-auth/myproject -b feature/auth]
[Run npm install]
[Run npm test -- 47 passing]

Worktree ready at ~/Development/worktrees/feature-auth/myproject
Tests passing (47 tests, 0 failures)
Ready to implement auth feature
<FORBIDDEN> - Creating worktrees in unignored project-local directories - Proceeding with implementation when baseline tests fail - Assuming worktree location without checking precedence - Modifying files in main workspace while in worktree context - Leaving orphaned worktrees after feature completion - Skipping safety verification for speed </FORBIDDEN><CRITICAL> ## Self-Check

Before reporting worktree ready -- if ANY unchecked, STOP and resolve:

  • Directory location follows precedence (override > default)
  • Project-local path verified gitignored (or global path used)
  • git worktree add completed successfully
  • Dependencies installed for project type
  • Baseline tests pass in new worktree</CRITICAL>

Integration

Called by:

  • design-exploration (Phase 4) -- REQUIRED when design is approved and implementation follows
  • Any skill needing isolated workspace

Pairs with:

  • finishing-a-development-branch -- REQUIRED for cleanup after work complete
  • executing-plans -- Work happens in this worktree (supports both batch and subagent modes)

<FINAL_EMPHASIS> Worktree isolation protects the main workspace from experimental damage. Skipping safety verification causes repository pollution requiring manual cleanup. Proceeding without baseline tests makes it impossible to distinguish new bugs from pre-existing failures. Take the time to do it right. </FINAL_EMPHASIS>

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.