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

using-git-worktrees

Skill1 starsChanged 4 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.

139 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use diagnosing-superpowers, chinese-git-workflow 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.
  • 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

We split this skill into the rules it gives an agent

11 rules. 0 are common, 7 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 132 edited versions we read keep these.

  • 7

    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. Very specific:

    NEVER START REPO EDITS IN A SHARED CHECKOUT — one where Step 1 reports git-dir equal to common-dir — WHATEVER BRANCH IT IS ON.

    line 7
  2. Distinctive:

    Skip creation: when the user explicitly says to stay, or Step 1 confirms a linked worktree owned by this task or the harness.

    line 19
  3. Distinctive:

    Read the submodule line first: inside a submodule the two directories match without a linked worktree.

    line 39
  4. Distinctive:

    Write every resource and dirty change into the inventory, by who created it.

    line 43
  5. Very specific:

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

    line 58
  6. Distinctive:

    Create from the proven base and enter:

    line 101
  7. Distinctive:

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

    line 116
  8. Very specific:

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

    line 117
  9. Distinctive:

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

    line 134
  10. Distinctive:

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

    line 141
  11. Very specific:

    Read references/checkpointing.md when the task will make more than one commit: the unit, and what git commit does not grant.

    line 160

“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
<EXTREMELY-IMPORTANT> NEVER START REPO EDITS IN A SHARED CHECKOUT — one where Step 1 reports `git-dir` equal to `common-dir` — WHATEVER BRANCH IT IS ON. Create or enter a dedicated workspace — a git worktree unless the user or project says otherwise — *before* the first edit, unless the user explicitly okayed the current checkout. Writing anything under `.sdlc-skills/` is not a repo edit here; product code, tests, and project gates are. </EXTREMELY-IMPORTANT>

Using Git Worktrees

When to use

  • Skip creation when the user explicitly says to stay, or Step 1 confirms a linked worktree owned by this task or the harness. Reuse its current workspace and baseline record; retain Step 5 checkpoints. Skip read-only work.

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 this:

    git rev-parse --show-toplevel
    git status --short --branch
    git rev-parse --show-superproject-working-tree   # non-empty: you are in a submodule
    git_dir="$(cd "$(git rev-parse --git-dir)" && pwd -P)"
    common_dir="$(cd "$(git rev-parse --git-common-dir)" && pwd -P)"
    [ "$git_dir" != "$common_dir" ] && echo "already inside a linked worktree"
    git worktree list
  2. Read the submodule line first: inside a submodule the two directories match without a linked worktree.
  3. Detached or host-owned checkout with unknown owner → do not nest, attach, switch, or clean it.
  4. Write every resource and dirty change into the inventory, by who created it. Never stash dirty state you do not own.
  5. Planned in another workspace → rerun 1 before the first product edit.

Step 2: Prove the base

  1. Take the base from direct user or project guidance. None → the current branch this task started from. Detached HEAD or conflicting guidance → ask and stop. Record its revision and remote freshness:

    git fetch origin "$BASE"          # only with network authority; otherwise record "not fetched"
    git rev-parse "$BASE" "origin/$BASE"
  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}}. Check collisions:

    git check-ref-format --branch "$BRANCH"
    git show-ref --verify --quiet "refs/heads/$BRANCH" && echo "local branch exists"
    git show-ref --verify --quiet "refs/remotes/origin/$BRANCH" && echo "remote branch exists"

    Anything prints → pick another name. Never overwrite or reuse.

  2. Pick the mechanism, first that applies: user instruction → project guidance → a harness-native worktree command (with the name above, HEAD at the proven base; skip to Step 4) → the steps below.
  3. Inside a submodule → stop here. Create an owned branch in the submodule and write an explicit plan for the parent gitlink; never run the rest of Step 3 from the superproject's paths. Otherwise choose the directory and prove it is ignored; a user-given path wins. A common git directory that is not a checkout's .git — bare repository, separate git directory — has no main checkout: ask where the worktree goes and stop.

    [ -z "$(git rev-parse --show-superproject-working-tree)" ] || echo "SUBMODULE: stop"
    root="${common_dir%/.git}"
    [ "$root" != "$common_dir" ] && git -C "$root" rev-parse --is-inside-work-tree >/dev/null 2>&1 ||
      echo "NO MAIN CHECKOUT: ask where the worktree goes"
    cd "$root"
    dir=".worktrees"
    git check-ignore -q "$dir/" || echo "$dir/ is not ignored"
  4. That line printed → exclude it locally; that is the whole change. Never add {{dir}}/ to .gitignore in any checkout: local commit authority covers task checkpoints, not a project change nobody requested.

    printf '%s/\n' "$dir" >> "$common_dir/info/exclude"
  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. worktree add or cd fails on a sandbox or permission boundary → try a path the boundary allows, confirmed with the user. 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. Red cell you cannot attribute, or 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 edit requests, branch/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. git-dir against 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, not once at the end — when the user or project policy authorizes local commits. None recorded → ask once for this task and record the answer; after a yes, never ask per checkpoint. A checkpoint never grants push, publication, or integration authority. </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 gate, and commit locally under the recorded authority.
  2. Candidate 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 gate 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 gate is slow — I'll run it once at the end"Then a red gate at the end leaves every change a suspect. The smallest gate 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 when the task will make more than one commit: the unit, and what git commit does not grant.
  • A gate written during planning lands on whatever branch the shared checkout is on.
  • 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 tell. 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.