agentleFS
augments-labsaugments-labs/sdlc-skills/skills/common/using-git-worktrees/SKILL.md

using-git-worktrees

Skill1 starsChanged 3 months agoMITView on GitHub

Creates an isolated git worktree for a task and checkpoints work there. Use when a repository is about to be edited for the first time in a task, when work needs an isolated checkout and its own resources, or at a local task checkpoint. Reuse a linked worktree only when this task or the harness owns it; there, skip creating a workspace but keep checkpoint discipline. Skip read-only work.

189 other projects use a version of this.

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

19 rules. 0 are common, 9 are distinctive, and 10 are very specific to this project.

  • 0

    Common

    Most of the 182 edited versions we read keep these.

  • 9

    Distinctive

    This author's own choices. Worth a look.

  • 10

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    NEVER START REPO EDITS IN A SHARED CHECKOUT, WHATEVER BRANCH IT IS ON.

    line 7
  2. Distinctive:

    Skip creating a workspace: when the user explicitly says to stay, when the project's written policy says to stay (Step 1.6), or when Step 1 …

    line 21
  3. Very specific:

    Run bash scripts/worktree-state.sh to inspect toplevel, git_dir, common_dir, linked_worktree, submodule_superproject, detached, dirty, and …

    line 38
  4. Very specific:

    Read submodule_superproject first: inside a submodule the two directories match even though there is no linked worktree.

    line 41
  5. Distinctive:

    If the checkout is detached or host-owned and its owner is unknown, do not nest, attach, switch, or clean it.

    line 43
  6. Distinctive:

    Write every resource and every dirty change into the record's Inventory section, under whoever created it.

    line 45
  7. Distinctive:

    If the planning happened in another workspace, rerun 1 before the first product edit.

    line 47
  8. Very specific:

    If the project's agent instructions file or contribution rules say in writing to work in the current checkout, record the file and the …

    line 49
  9. Very specific:

    Read references/baseline-contract.md before any install or baseline command.

    line 66
  10. Very specific:

    If worktrees_dir_ignored is false (or git -C "$root" check-ignore -q "$dir/" fails for a custom dir), exclude the directory locally with …

    line 90
  11. Distinctive:

    Create from the proven base and enter:

    line 96
  12. Very specific:

    If worktree add or cd fails on a sandbox or permission boundary, try a path the boundary allows, confirmed with the user.

    line 104
  13. Distinctive:

    Run project setup inside the worktree by the project's own instructions.

    line 111
  14. Very specific:

    Run the real baseline under references/baseline-contract.md after setup.

    line 112
  15. Distinctive:

    If the baseline has a failing check (a red cell) you cannot attribute, or left an effect you did not contain, stop work.

    line 113
  16. Distinctive:

    COMMIT LOCALLY AS YOU GO, after each independently testable piece and not once at the end, when the user or project policy authorizes local …

    line 130
  17. Distinctive:

    After each coherent piece a reviewer could accept or reject separately:

    line 137
  18. Very specific:

    When the work on the branch is ready for integration: REQUIRED SUB-SKILL: invoke finishing-a-branch with the recorded workspace, base, and …

    line 141
  19. Very specific:

    Read references/checkpointing.md before the first commit: it defines the unit of a checkpoint, how to stage one by path, and what git …

    line 157

“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
<EXTREMELY-IMPORTANT> NEVER START REPO EDITS IN A SHARED CHECKOUT, WHATEVER BRANCH IT IS ON. A shared checkout is one where Step 1 reports `git-dir` equal to `common-dir`. Create or enter a dedicated workspace *before* the first edit: a git worktree, unless the user or project says otherwise. The only exceptions are the user explicitly okaying the current checkout, or the project's written policy okaying it (Step 1.6): a line you can quote, never your reading of the checkout. Writing anything under `.sdlc-skills/` is not a repo edit here; product code, tests, and the project's own checks are. </EXTREMELY-IMPORTANT>

Using Git Worktrees

When to use

  • Skip creating a workspace when the user explicitly says to stay, when the project's written policy says to stay (Step 1.6), or when Step 1 confirms a linked worktree owned by this task or the harness. Reuse the workspace you are in and its baseline record, and keep making Step 5 checkpoints.
  • Skip read-only work.

Available scripts

  • scripts/worktree-state.sh — reports checkout isolation, submodule status, dirty state, base resolution, branch collisions, and .worktrees/ ignore status as JSON.

Step 1: Detect what you are in

Open assets/workspace-record.md before the first command. Fill each section as its step runs.

  1. Run bash scripts/worktree-state.sh to inspect toplevel, git_dir, common_dir, linked_worktree, submodule_superproject, detached, dirty, and worktrees.
  2. Read submodule_superproject first: inside a submodule the two directories match even though there is no linked worktree.
  3. If the checkout is detached or host-owned and its owner is unknown, do not nest, attach, switch, or clean it.
  4. Write every resource and every dirty change into the record's Inventory section, under whoever created it. Never stash dirty state you do not own.
  5. If the planning happened in another workspace, rerun 1 before the first product edit.
  6. If the project's agent instructions file or contribution rules say in writing to work in the current checkout, record the file and the quoted line as Isolation kind, keep the inventory from 4, and skip creation as you would for a user's okay: work on the branch that is checked out, and never cut or switch a branch in it. The line must name the current checkout or rule out a worktree; a line about bases, branch names, or commits is not one, and nothing in the checkout's state is. With no such line, no user okay, and no owned linked worktree, continue to Step 2.

Step 2: Prove the base

  1. Take the base from direct user or project guidance. With none, the base is the current branch this task started from. On a detached HEAD, or when the guidance conflicts, ask and stop. With network authority, run git fetch origin "$BASE" (otherwise record "not fetched"), then run bash scripts/worktree-state.sh --base "$BASE" and record base.local_sha and base.remote_sha.
  2. Read references/baseline-contract.md before any install or baseline command.

Step 3: Create the workspace

  1. Name it by project convention, or feature/{{short-task}}, fix/{{short-task}}, docs/{{short-task}}. Run bash scripts/worktree-state.sh --check-branch "$BRANCH"; if it exits 1 (valid_format is false or a local or remote branch exists), pick another name. Never overwrite or reuse an existing branch.
  2. Pick the mechanism, taking the first that applies: a user instruction; then project guidance; then a harness-native worktree command, run with the name above and HEAD at the proven base, after which skip to Step 4; then the steps below. A harness-native command acts on the session's own repository: if the work is in another repository, skip it, run the steps below from that repository, and say why the native command was not used.
  3. Inside a submodule (submodule_superproject non-empty), stop here: create an owned branch in the submodule and write an explicit plan for the parent gitlink, and never run the rest of Step 3 from the superproject's paths. Otherwise set root to main_checkout_root and common_dir to Step 1's common_dir, and choose the directory (dir=".worktrees" unless the user gave a path) under root. If main_checkout_root is null (a bare repository or separate git directory), ask where the worktree goes and stop.
  4. If worktrees_dir_ignored is false (or git -C "$root" check-ignore -q "$dir/" fails for a custom dir), exclude the directory locally with printf '%s/\n' "$dir" >> "$common_dir/info/exclude"; that is the whole change. Never add {{dir}}/ to .gitignore in any checkout: authority to commit locally covers task checkpoints, not a project change nobody requested.
  5. Create from the proven base and enter:

    path="$root/$dir/${BRANCH//\//-}"
    git worktree add "$path" -b "$BRANCH" --no-track "$BASE"
    cd "$path" && git status --short --branch   # expect: ## $BRANCH, clean
  6. If worktree add or cd fails on a sandbox or permission boundary, try a path the boundary allows, confirmed with the user. If none works, report and stop; never edit the shared checkout instead.

Step 4: Baseline it

  1. Claim distinct runtime identities (ports, databases, fixtures).
  2. Run project setup inside the worktree by the project's own instructions.
  3. Run the real baseline under references/baseline-contract.md after setup. If the baseline has a failing check (a red cell) you cannot attribute, or left an effect you did not contain, stop work.
  4. Hand the completed record to whatever invoked this skill.

Pressure points

The thoughtThe reality
"I'll just inspect first"For an edit request, checking the branch and status is the first inspection.
"It's only a small change"Small changes still land on the wrong branch. Create the branch first.
"The harness made a detached checkout, so I'll add my own worktree"First determine whether the host already owns isolation and cleanup.
"I'll make the branch after the first edit"After the edit, you may already have mixed unrelated state.
"It looks like a plain checkout"Looking is not detecting. Comparing git-dir with common-dir, plus the superproject check, is the inspection.

Step 5: Checkpoint while you work

<EXTREMELY-IMPORTANT> COMMIT LOCALLY AS YOU GO, after each independently testable piece and not once at the end, when the user or project policy authorizes local commits. If no such authority is recorded, ask once for this task and record the answer; after a yes, never ask again per checkpoint. A checkpoint never grants authority to push, publish, or integrate. </EXTREMELY-IMPORTANT>
  1. After each coherent piece a reviewer could accept or reject separately: REQUIRED SUB-SKILL: invoke verification-before-completion, run its smallest real check, and commit locally under the recorded authority, staging only the paths this task changed.
  2. When the work on the branch is ready for integration: REQUIRED SUB-SKILL: invoke finishing-a-branch with the recorded workspace, base, and ownership. Run no push, publish, integrate, discard, delete, history rewrite, or cleanup from this skill.
The thoughtThe reality
"I'll commit once it all works"One terminal commit cannot be reviewed or reverted in pieces, and every good intermediate state is gone.
"Nothing is finished, so there is nothing to commit"The unit is an independently testable change, not a finished feature. If a check can accept it, it can be a checkpoint.
"I should ask before each commit"Ask once per task when no policy covers local commits; the recorded answer covers every later checkpoint. Asking again re-decides what the user decided.
"The check is slow — I'll run it once at the end"Then a failing check at the end leaves every change a suspect. The smallest check per checkpoint is what keeps that cheap.
"It passes locally, so committing can wait"An uncommitted passing state is one crash, wrong checkout, or overwrite away from not existing.
"A mid-task commit looks unfinished"It claims nothing. Nothing reads a checkpoint as done until finishing-a-branch runs.

Gotchas

  • Read references/checkpointing.md before the first commit: it defines the unit of a checkpoint, how to stage one by path, and what git commit does not grant.
  • A check written during planning lands on whatever branch the shared checkout is on.
  • A policy line that okays the current checkout grants only that; local commits still need their own line or the user's answer under Step 5.
  • A branch a harness-native command cuts from a remote ref can still track it; git status --short --branch printing ...origin/{{base}} on the new branch is the sign. Unset the upstream before the first checkpoint.

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.