agentleFS
cedaniel200cedaniel200/atlas-template/.agents/skills/using-git-worktrees/SKILL.md

using-git-worktrees

Skill3 starsChanged 20 days agoMITView on GitHub

Use at session start, when creating change artifacts, or before implementing a plan - resolves the workspace policy (worktree by default, human-requested feature branch as exception) and never writes on the base branch; prefers native worktree tools over git worktree

189 other projects use a version of this, 142 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

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. 0 are common, 15 are distinctive, and 8 are very specific to this project.

  • 0

    Common

    Most of the 182 edited versions we read keep these.

  • 15

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Ensure work happens in an isolated workspace.

    line 11
  2. Distinctive:

    Never fight the harness.

    line 15
  3. Distinctive:

    Workspace policy: every change is written on its own branch.

    line 17
  4. Distinctive:

    If the user declines, work in place only when they asked for a simple feature branch and the working tree is clean.

    line 56
  5. Very specific:

    Do you already have a way to create a worktree?

    line 66
  6. Distinctive:

    Check your instructions for a declared worktree directory preference.

    line 79
  7. Very specific:

    Check for an existing project-local directory: ls -d .worktrees (preferred) or ls -d worktrees.

    line 80
  8. Very specific:

    If both exist, .worktrees wins.

    line 81
  9. Very specific:

    If NOT ignored: add it to .gitignore, commit, then proceed.

    line 92
  10. Distinctive:

    Sandbox fallback: if git worktree add fails with a permission error, tell the user the sandbox blocked it and work in the current directory …

    line 103
  11. Very specific:

    Run the project's install command from AGENTS.md § Comandos (INSTALL_COMMAND).

    line 108
  12. Very specific:

    Run the project's test command (TEST_COMMAND).

    line 113
  13. Distinctive:

    Write on the base branch: isolate the change or stop and ask

    line 147
  14. Distinctive:

    Create a worktree when Step 0 detects existing isolation

    line 148
  15. Very specific:

    Use git worktree add when you have a native worktree tool (e.g., EnterWorktree)

    line 149
  16. Distinctive:

    Create a worktree without verifying it's ignored (project-local)

    line 151
  17. Distinctive:

    Run Step 0 detection first

    line 156
  18. Distinctive:

    Prefer native tools over git fallback

    line 157
  19. Distinctive:

    Follow directory priority: explicit instructions > existing project-local directory > default

    line 158
  20. Distinctive:

    Verify the directory is ignored for project-local

    line 159
  21. Very specific:

    Use the project's INSTALL_COMMAND / TEST_COMMAND

    line 160
  22. Distinctive:

    Verify a clean test baseline

    line 161
  23. Distinctive:

    Read only when needed:

    line 165

“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

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.

Workspace policy: every change is written on its own branch. The default is a worktree; a simple feature branch in the main checkout is an exception the human requests explicitly. The base branch is never written to. This skill applies at three trigger points:

  1. Session start — report the current branch, whether the working directory is a worktree and the active change. Do not create anything yet.
  2. Before creating change artifacts — isolate first if the current branch is the base branch.
  3. Before implementing a plan — same check.

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

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/null

If GIT_DIR != GIT_COMMON (and not a submodule): you are already in a linked worktree. Skip to Step 2. Do NOT create another worktree. Report: "Already in isolated workspace at <path> on branch <name>." (Detached HEAD: note that branch creation is needed at finish time.)

If GIT_DIR == GIT_COMMON (or in a submodule): you are in a normal repo checkout. Resolve consent from the preference already declared in AGENTS.md or the session instructions. When the declared default is a worktree, do not ask again. Ask only when no preference exists:

"Would you like me to set up an isolated worktree? It protects your current branch from changes."

If the user declines, work in place only when they asked for a simple feature branch and the working tree is clean. Never work on the base branch: isolate, or stop and ask. Record the exception in the change.

Step 1: Create Isolated Workspace

Two mechanisms. Try them in this order.

1a. Native Worktree Tools (preferred)

Do you already have a way to create a worktree? It might be a tool named like EnterWorktree, WorktreeCreate, a /worktree command, or a --worktree flag. If so, use it and skip to Step 2. Native tools handle directory placement, branch creation and cleanup automatically; using git worktree add when you have one creates phantom state your harness cannot see or manage.

1b. Git Worktree Fallback

Only if Step 1a does not apply.

Directory Selection

Explicit user preference always beats observed filesystem state.

  1. Check your instructions for a declared worktree directory preference.
  2. Check for an existing project-local directory: ls -d .worktrees (preferred) or ls -d worktrees. If both exist, .worktrees wins.
  3. Otherwise default to .worktrees/ at the project root.

Safety Verification (project-local directories only)

MUST verify the directory is ignored before creating the worktree:

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

If NOT ignored: add it to .gitignore, commit, then proceed. Prevents accidentally committing worktree contents.

Create the Worktree

path="$LOCATION/$BRANCH_NAME"
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"

Sandbox fallback: if git worktree add fails with a permission error, tell the user the sandbox blocked it and work in the current directory instead.

Step 2: Project Setup

Run the project's install command from AGENTS.md § Comandos (INSTALL_COMMAND). If it is N/A, skip this step. Do not guess stack-specific commands.

Step 3: Verify Clean Baseline

Run the project's test command (TEST_COMMAND). If it is N/A, state that there is no automated baseline.

If tests fail: report failures and ask whether to proceed or investigate. If they pass: report ready.

Report

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

Quick Reference

SituationAction
Already in linked worktreeSkip creation (Step 0)
In a submoduleTreat as normal repo (Step 0 guard)
Native worktree tool availableUse it (Step 1a)
No native toolGit worktree fallback (Step 1b)
.worktrees/ existsUse it (verify ignored)
worktrees/ existsUse it (verify ignored)
Both existUse .worktrees/
Neither existsCheck instruction file, then default .worktrees/
Directory not ignoredAdd to .gitignore + commit
Permission error on createSandbox fallback, work in place
Tests fail during baselineReport failures + ask
INSTALL_COMMAND is N/ASkip dependency install

Red Flags

Never:

  • Write on the base branch: isolate the change or stop and ask
  • Create a worktree when Step 0 detects existing isolation
  • Use git worktree add when you have a native worktree tool (e.g., EnterWorktree)
  • Skip Step 1a by jumping straight to Step 1b's git commands
  • Create a worktree without verifying it's ignored (project-local)
  • Skip baseline test verification
  • Proceed with failing tests without asking

Always:

  • Run Step 0 detection first
  • Prefer native tools over git fallback
  • Follow directory priority: explicit instructions > existing project-local directory > default
  • Verify the directory is ignored for project-local
  • Use the project's INSTALL_COMMAND / TEST_COMMAND
  • Verify a clean test baseline

References

Read only when needed:

  • references/common-mistakes.md — the five recurring mistakes and their fixes.

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.