worktrees
Skill1 starsChanged 4 months agoMITView on GitHub
Creating, finishing, recovering, and safely delegating git worktrees. Load this skill before creating a worktree, merging one back, cleaning one up, or handing one to a subagent — not at session start.
20 other projects use a version of this.
Adopted by
Most recently taken up by
- domengabrovsek/agent-configtheir own version, first seen Nov 8, 2026
- domengabrovsek/claudetheir own version, first seen Nov 8, 2026
- chewygumxx/agentic-librarytheir own version, first seen Nov 8, 2026
- delorenj/skillstheir own version, first seen Nov 7, 2026
- pumpkit-io/sdlctheir own version, first seen Nov 1, 2026
- theyoungastronauts/polaristheir own version, first seen Nov 1, 2026
Used with
Projects with it also use resolve-conflicts, debug 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.
ralphkraussSkillresolve-conflicts
Resolve git merge conflicts or re-apply changes from a stale branch onto current main. Use when user says "resolve conflicts", "merge conflicts", "rebase branch", "branch is behind", "re-apply changes", "port branch", or a branch is too far behind main to merge cleanly.
Also in 3 projects that use this
AnthropicSkilldebug
Structured debugging session — reproduce, isolate, diagnose, and fix. Trigger with an error message or stack trace, "this works in staging but not prod", "something broke after the deploy", or when behavior diverges from expected and the cause isn't obvious.
Also in 4 projects that use this
GoogleSkillprototype
Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.
Also in 4 projects that use this
GoogleSkillimprove-codebase-architecture
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
Also in 4 projects that use this
MicrosoftSkillhandoff
Compact the current conversation into a handoff document for another agent to pick up.
Also in 6 projects that use this
BlockSkillplan
Draft a TDD, PRD, or lightweight plan in the conversation without committing it.
Also in 3 projects that use this
- +1 more from google
Other versions20 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 20
- GetStream/stream-chat-react★ 844same name
- akitaonrails/my-skills★ 283same name
- maragudk/skills★ 49same name
- nilecui/SkillsBase★ 27same name
- domengabrovsek/agent-config★ 22same name
- domengabrovsek/claude★ 22same name
- delorenj/skills★ 17same name
- ariadoss/superskills★ 12same name
- theyoungastronauts/polaris★ 4same name
- divanc/skills★ 3same name
10 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- templates/copilot-instructions.mdCopilot instructions
- speckit-analyzeSkill
- speckit-checklistSkill
- speckit-clarifySkill
- speckit-constitutionSkill
- speckit-convergeSkill
- speckit-implementSkill
- speckit-planSkill
- speckit-specifySkill
- speckit-tasksSkill
- speckit-taskstoissuesSkill
- backlogSkill
- code-intelligenceSkill
- field-notesSkill
- operator-backlog-newitemSkill
- operator-backlog-refinementSkill
- operator-backlog-scrumSkill
- peer-agentsSkill
- request-auditSkill
- spec-drivenSkill
The file
We split this skill into the rules it gives an agent
8 rules. 0 are common, 5 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 20 edited versions we read keep these.
5
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
Use that for anything identifying the project — project directory, .specify/ init, config lookups.
- Distinctive: line 45
Prefer the operator commands.
- Distinctive: line 80
Never create a worktree inside another worktree.
- Distinctive: line 82
Leave worktrees you did not create alone.
- Distinctive: line 87
Every probe script, every reproduction written to confirm a bug, every scratch copy kept for a diff.
- Distinctive: line 118
Verify the tree before you act on the findings: If a subagent mentions in passing that something of yours was lost, stop and check git …
- Very specific: line 134
Only after operator confirms the owner is gone — operator worktree recover reports, it does not decide for you.
- Very specific: line 136
If there are uncommitted changes, commit them to a wip/ branch first (that is what --preserve does), then continue.
“Common” is measured: kept by at least 6 in 10 of the 20 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.
Files
Worktrees
Operator assigns your worktree before your session starts. You need this skill only when you are changing the set of worktrees, not to work in the one you were given.
Resolving the primary root
Inside a worktree, git rev-parse --show-toplevel returns the worktree. The
first record of git worktree list --porcelain is always the primary checkout,
from anywhere in the repo:
repo_root=$(git worktree list --porcelain | head -1 | cut -d' ' -f2-)$repoRoot = (git worktree list --porcelain | Select-Object -First 1) -replace '^worktree 'Use that for anything identifying the project — project directory, .specify/
init, config lookups. Using the worktree path instead mints a duplicate project id
and splits the project's state in two, silently.
It is also why "walk up until you find AGENTS.md" is not a way to find the repo
root: in a monorepo it finds a subproject's file, and inside a worktree it finds
the worktree's own tracked copy. Neither is the primary checkout.
Layout
<repoRoot>/.worktrees/<name>, where <name> is the branch with / replaced by
- (feat/login → .worktrees/feat-login). /.worktrees/ must be in the
tracked .gitignore — .git/info/exclude does not reach other clones.
operator worktree new adds the rule if it is absent, reports that it did, and
leaves it unstaged for you to commit deliberately. It recognises a rule you
wrote yourself in any spelling git accepts and leaves it alone.
Lifecycle
Prefer the operator commands. They record the worktree against your work item, so
liveness recovery can find it later; a plain git worktree add leaves a tree
nobody can attribute to a claim.
operator worktree new --instance NAME --item REF [--project SUB] [--branch NAME] [--path PATH]
operator worktree finish --instance NAME [--item REF] [--into REF]
operator worktree recover [--preserve]A checkout is 1:1 with a work item: new takes the claim and creates the tree
together, and releases the claim again if the tree cannot be made — so a failed
create never leaves an item claimed by nobody.
finish refuses a tree with uncommitted changes rather than tidying it, and
deletes the branch only when --into already contains it. Both refusals are the
point: the alternative to refusing is discarding work whose value only its author
knows.
recover reports and removes nothing. --preserve commits the uncommitted work
of an unclaimed tree, or one whose owner is provably gone, to a wip/ branch.
Underlying git, if you need it:
git -C "$repo_root" worktree add .worktrees/feat-login -b feat/login
cd "$repo_root/.worktrees/feat-login"
# work, commit
cd "$repo_root" && git merge --no-ff feat/login
git worktree remove .worktrees/feat-login && git branch -d feat/loginRules
- One worktree per branch — git refuses two.
- Never create a worktree inside another worktree. Resolve the primary root first.
cdout before removing.- Leave worktrees you did not create alone. Another agent may be live in one.
- Worktree branches merge to
main. There is no integration branch.
Scratch files never go in a checkout
Every probe script, every reproduction written to confirm a bug, every scratch copy kept for a diff. A script with a relative path writes wherever the process happens to be, and for an agent that is almost always somebody's checkout.
scratch=$(mktemp -d)$scratch = New-Item -ItemType Directory -Path (Join-Path $env:TEMP ([guid]::NewGuid()))Tell your subagents the same thing, by name. They run their own shell in your tree and you see only their output.
git status will not save you — git does not track empty directories, so an
empty stray is invisible to it. A checkout can report perfectly clean with
artifacts sitting in its root. Clean up before you finish, not later: an artifact
found afterwards has no provenance, and every explanation fits it equally well.
Three agents once spent an evening diagnosing a working-directory bug that did not
exist, on the evidence of directories their own review subagents had left behind.
Handing a worktree to a subagent
Commit before you delegate. Staging is not enough. A commit is the only state
a subagent cannot casually destroy. Point reviewers at git diff main...HEAD, not
git diff --staged.
Forbid mutating git commands by name: stash, checkout, reset, clean,
restore, rebase, commit, add. "Do not write outside tmp" does not cover git
plumbing, which creates no new files.
Verify the tree before you act on the findings. If a subagent mentions in
passing that something of yours was lost, stop and check git status and
git stash list before reading anything else it reported. Work that was
git add-ed survives a dropped stash as dangling objects:
git fsck --unreachable
git cat-file -p <blob> # grep for a string unique to your changeA subagent that ran git checkout or reset --hard instead leaves nothing to
recover at all. A reviewer once destroyed 454 lines this way and mentioned it in
passing in an otherwise clean review; see docs/rationale.md.
Recovering someone else's worktree
Only after operator confirms the owner is gone — operator worktree recover
reports, it does not decide for you. Never stash, reset, clean, or delete.
If there are uncommitted changes, commit them to a wip/ branch first (that is
what --preserve does), then continue. A crashed agent's uncommitted work is the
most expensive thing in the tree.
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
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.

