{"name":"work-in-external-repo","title":"Work in an external repository","description":"Work in a repository that is not the current working directory: establish the target by name, prove the checkout by its origin remote before writing, refresh the base ref, build in a dedicated worktree instead of a shared checkout, and name the repository, branch, worktree and commits in the result. Use when a change, a branch or a pull request is requested against another repository.","compatibility":"Any machine with git and a shell the agent can run commands in; nothing to install. Locating a checkout needs read access to the roots repositories live under. Refreshing the base ref needs the network: where the fetch fails the skill reports the ahead/behind as unknown rather than branching blind. A GitHub CLI is optional and used only where a pull request is asked for. Output is the change plus the repository, branch, worktree path and commits it landed in.","allowedTools":"Read Write Edit Grep Glob Bash","license":"MIT","kind":"signals","useWhen":"writing to a repository that is not this working directory","group":"workflow","lifecycle":"release","version":"1.0.0","author":"crissmoldovan","install":["npx skills add crissmoldovan/agent-skills --skill work-in-external-repo"],"asks":["The change goes in <owner>/<repo>, not in this working directory. Find the checkout if it is on\nthis machine, and confirm it is the right one by its origin remote before you write anything.\nIf you find none, or more than one, tell me what you found and let me pick — do not choose.","Before you branch: fetch the base and tell me how far behind that checkout is. If it is more\nthan a handful of commits, I want to hear the number before you build anything on it.","Another agent is working in that repository right now. Do your work in a worktree of your own\noff origin/main, and do not run stash, reset or checkout -- anywhere in the shared checkout.\nStage only the paths you actually wrote.","When you are done, tell me which repository and branch the commits are on, the worktree path,\nand whether you removed it. \"Done, 2 commits\" tells me nothing about where they are."],"commands":["# 1. Locate, then prove it — a matching directory name is not proof of anything.\nfind <search-root> -maxdepth 3 -type d -name .git\ngit -C <candidate> remote get-url origin       # must equal the named target\ngit -C <candidate> worktree list               # what is already checked out, and where\n\n# 2. Refresh the base. Left = commits you are behind; right = commits you are ahead.\ngit -C <candidate> fetch origin\ngit -C <candidate> rev-list --left-right --count origin/main...HEAD\n\n# 3. Branch into a tree of your own, off the ref you just fetched.\ngit -C <candidate> worktree add -b feat/<slug> <parent>/<repo>-wt-<slug> origin/main\n\n# 4. Work there, staging by explicit path only.\ngit -C <parent>/<repo>-wt-<slug> add <path>\ngit -C <parent>/<repo>-wt-<slug> commit -F <message-file>\n\n# 5. Hand back: remove the tree, or say in the result that it remains.\ngit -C <candidate> worktree remove <parent>/<repo>-wt-<slug>\ngit -C <candidate> worktree prune"],"documents":[],"body":"# Work in an external repository\n\nThe work is wanted somewhere else — another repository, on this machine or not yet on it — and\nevery way that goes wrong is quiet. The agent edits a checkout whose directory has the right\nname and belongs to a fork. It works directly in a checkout another session is holding. It\nbranches off a base ref last fetched in a different month. It clones to a path it invented,\nproducing a second copy nobody will find. And at the end it reports two commits and a green\ntest run without ever naming a repository, so the reader — looking at their own terminal —\nconcludes the work landed here.\n\nNone of these announce themselves. Every command succeeds, the diff looks right, and the\ndamage surfaces in somebody else's session or in a pull request that conflicts from its first\nline.\n\nThis skill owns the route to the target and the tree the work happens in: establishing which\nrepository is meant, proving the checkout is that repository, getting a current base, working\nsomewhere nobody else is standing, and saying afterwards where the work went. It does **not**\nown the change — `land-complex-change` contains that. It does not own the description of the\ndiff (`describe-changes`), the review loop (`request-blocks-review`), or the shape of a status\nreport (`report-progress`); it hands that report one line it must carry, which is where the\nwork landed.\n\n### What this skill does not own\n\n| The job | Whose it is | What this skill does with it |\n|---|---|---|\n| Containing the change once you are in the right tree | `land-complex-change` | Hands over a clean worktree at a known base; declares no touch-set of its own. |\n| Saying what the landed diff did | `describe-changes` | Calls it after the commits exist, in the worktree it created. |\n| The review loop over the pull request | `request-blocks-review` | Hands over the repository, branch and head sha; runs no review of its own. |\n| The shape of progress reports | `report-progress` | Supplies the destination line every report of external work owes. |\n| What the child agents are doing | `agent-lifecycle` | Consumes it; two agents in one repository is exactly when it is needed. |\n\nInstall the companions with `npx skills add crissmoldovan/agent-skills`.\n\n## When to Use\n\n- The request names **another repository** — by owner and name, by URL, or by a shorthand only\n  the user can resolve — and the change belongs there rather than here.\n- A branch, a commit or a pull request is wanted in a repository that is not this working\n  directory.\n- The target may not be on this machine at all, and a clone is on the table.\n- The target **is** on this machine as a checkout a person or another session may be using.\n- Two agents are working in one repository at the same time, whatever the task.\n- A previous session left a worktree behind and this session continues that work.\n\nDo not use it for work in the current repository: everything here is overhead you have already\npaid. Do not use it for read-only inspection of another repository — locating a checkout,\nreading its files, running `git log` in it — that changes nothing and needs no worktree; only\nthe write turns this on. Do not use it as a plan for the change itself; the moment the tree is\nright, `land-complex-change` takes over and this skill is finished until the result is written.\n\n## Prerequisites\n\n1. **The target as a remote, not as a directory.** `owner/name`, or a clone URL.\n   **Complete when:** the target is written down in a form that would identify the same\n   repository on a machine with no local checkouts at all.\n2. **The base ref the work branches from.** `main` is a guess, not a default; some repositories\n   release from another branch.\n   **Complete when:** the base ref is named, or the user has confirmed the repository's default.\n3. **Somewhere worktrees may be created.** A parent directory that exists and is not inside the\n   shared checkout.\n   **Complete when:** the parent path is known and the user approved it if it is new.\n4. **Whether the work may be pushed.** Push access, a fork, or an agreement that this ends at a\n   local branch.\n   **Complete when:** the end state of the branch is agreed before the first commit, not\n   discovered at the push.\n5. **Knowledge of who else is in there.** Another agent, another session, a person with a dirty\n   tree.\n   **Complete when:** `git -C <repo> worktree list` and `git -C <repo> status` have been read,\n   and a dirty shared tree is treated as occupied.\n\n## Procedure\n\n1. **Establish the target repository by name, before anything else.** Never assume the current\n   repository is the target — the working directory is where the conversation happens, not\n   where the work belongs. Resolve the request to `owner/name` or a URL. If it arrives as \"the\n   skills repo\" or \"the API one\", ask which remote that is; do not resolve a nickname against\n   the filesystem and take the first hit.\n   **Complete when:** the target is stated as a remote, and nothing has yet been read from a\n   directory chosen because its name looked right.\n\n2. **Locate before creating.** Search the roots repositories live under —\n   `find <search-root> -maxdepth 3 -type d -name .git` — and read\n   `git -C <candidate> worktree list`, which shows checkouts of that repository you would\n   otherwise clone a second time. Then prove the candidate:\n   `git -C <candidate> remote get-url origin` must equal the target. **A directory with the\n   right name is not proof**: forks, vendored copies and abandoned clones all carry the name of\n   the thing they were copied from. If **zero** candidates survive, go to step 3. If **several**\n   do, ask the user which one, listing each candidate's origin URL and current branch — picking\n   the newest or the shortest path is a guess wearing a decision's clothes.\n   **Complete when:** the chosen path's `origin` matches the named target, confirmed before any\n   write rather than after the first edit; or the user has chosen from candidates you listed.\n\n3. **If it is not on this machine, confirm the destination before cloning.** Never invent a\n   parent directory, and never clone into the current repository's tree. Propose a path, get it\n   confirmed, then `git clone <url> <path>`. Clone fully: a `--depth` clone makes the ahead/\n   behind count in the next step meaningless and can refuse a `worktree add` from an old ref.\n   **Complete when:** the clone exists at a path the user named or approved, and its `origin` is\n   the target's URL.\n\n4. **Refresh the base ref and report ahead/behind.** `git -C <repo> fetch origin`, then\n   `git -C <repo> rev-list --left-right --count origin/<base>...HEAD` — the left number is how\n   far **behind** the local ref is, the right is how far **ahead**. Say both out loud. A stale\n   base is the default state of a checkout nobody has touched, not an exception, and a checkout\n   hundreds of commits behind looks exactly like a current one from the inside. If the fetch\n   fails, say the ahead/behind is unknown; do not branch blind and call it current.\n   **Complete when:** the fetch ran in this session and both counts are stated, or the failure is\n   reported in place of them.\n\n   The number is not what makes the branch correct — step 5 branches from the fetched\n   `origin/<base>` regardless, so a stale local ref cannot contaminate it. It is what tells you\n   the shared checkout's *working files* are old, which matters the moment you read one to\n   decide what to write, and it predicts whether the eventual pull request opens clean or\n   arrives hundreds of commits behind its target.\n\n5. **Create a dedicated worktree on a new branch, never in the shared checkout.** The form is\n   `git worktree add -b <branch> <path> <base>`, run as\n   `git -C <repo> worktree add -b feat/<slug> <parent>/<repo>-wt-<slug> origin/<base>`. The third\n   argument is the base ref and it is not optional: omit it and git silently branches from\n   whatever HEAD the shared checkout is sitting on, which may be another session's half-finished\n   branch. Work in that new path only. Another session may be using the shared checkout, and its\n   branch, its index and its uncommitted files are not yours to move.\n   **Complete when:** the worktree exists outside the shared checkout, `git -C <worktree> status`\n   is clean, and the branch points at the ref fetched in step 4.\n\n6. **Keep off the shared tree: the forbidden operations.** In any tree another session or person\n   may be using — including the checkout you located in step 2 — never run `git stash`,\n   `git reset`, or `git checkout --`, and never rebase or amend a commit you did not create.\n   Each is silent by design: it prints almost nothing, it exits zero, and what it destroys is\n   somebody else's uncommitted work, which has no reflog to recover it from. Stage by explicit\n   path — `git -C <worktree> add <path>` — never a whole-tree stage, so a file you did not write\n   cannot ride along in your commit.\n   **Complete when:** every git command run outside your own worktree was read-only, and every\n   commit staged only paths you named.\n\n7. **Name the destination in every result.** Repository, branch, worktree path, commits by sha\n   and count. A result that does not name the repository invites the reader to assume the\n   current one — they are looking at their own terminal, and nothing in your answer contradicts\n   them. This line is owed in intermediate reports too, not only at the end.\n   **Complete when:** the answer states repository, branch, worktree path and commits, and a\n   reader who never saw a command of yours can tell which repository changed.\n\n8. **Clean up, or hand over in writing.** Either remove the tree —\n   `git -C <repo> worktree remove <path>` then `git -C <repo> worktree prune` — or say in the\n   result that it remains, where it is, and on which branch. A forgotten worktree blocks the\n   branch from being deleted (`git branch -d` refuses while a worktree holds it), leaves an\n   administrative entry in the parent repository, and hands the next session a second tree whose\n   purpose nobody remembers.\n   **Complete when:** the worktree is gone from `git -C <repo> worktree list`, or the result\n   names the path that survives and why it was kept.\n\n## Usage Examples\n\n```text\nThe change goes in <owner>/<repo>, not in this working directory. Find the checkout if it is on\nthis machine, and confirm it is the right one by its origin remote before you write anything.\nIf you find none, or more than one, tell me what you found and let me pick — do not choose.\n```\n\n```text\nBefore you branch: fetch the base and tell me how far behind that checkout is. If it is more\nthan a handful of commits, I want to hear the number before you build anything on it.\n```\n\n```text\nAnother agent is working in that repository right now. Do your work in a worktree of your own\noff origin/main, and do not run stash, reset or checkout -- anywhere in the shared checkout.\nStage only the paths you actually wrote.\n```\n\n```text\nWhen you are done, tell me which repository and branch the commits are on, the worktree path,\nand whether you removed it. \"Done, 2 commits\" tells me nothing about where they are.\n```\n\n### The sequence, end to end\n\n```bash\n# 1. Locate, then prove it — a matching directory name is not proof of anything.\nfind <search-root> -maxdepth 3 -type d -name .git\ngit -C <candidate> remote get-url origin       # must equal the named target\ngit -C <candidate> worktree list               # what is already checked out, and where\n\n# 2. Refresh the base. Left = commits you are behind; right = commits you are ahead.\ngit -C <candidate> fetch origin\ngit -C <candidate> rev-list --left-right --count origin/main...HEAD\n\n# 3. Branch into a tree of your own, off the ref you just fetched.\ngit -C <candidate> worktree add -b feat/<slug> <parent>/<repo>-wt-<slug> origin/main\n\n# 4. Work there, staging by explicit path only.\ngit -C <parent>/<repo>-wt-<slug> add <path>\ngit -C <parent>/<repo>-wt-<slug> commit -F <message-file>\n\n# 5. Hand back: remove the tree, or say in the result that it remains.\ngit -C <candidate> worktree remove <parent>/<repo>-wt-<slug>\ngit -C <candidate> worktree prune\n```\n\n## What it looks like\n\nA specimen, not a prompt. This is what the result should say when the work is\ndone and handed back.\n\n### A result that names where the work landed\n\n```text\nRepository: <owner>/<repo> — origin git@github.com:<owner>/<repo>.git. Not this working\ndirectory; nothing here changed.\nBranch: feat/<slug>, cut from origin/main at a1b2c3d, fetched in this session (0 behind).\nWorktree: <parent>/<repo>-wt-<slug> — still present, deliberately, for the review pass.\nCommits: 2 — 4d1f0c7, 9e8a210. Pushed to origin/feat/<slug>; no pull request opened.\n```\n\nEvery line of it is checkable by someone who saw none of the session: the repository is named\nas a remote rather than as a path, the base carries the sha it was cut from and the freshness\nof that ref, the worktree's survival is stated rather than left to be discovered, and the\ncommits are countable.\n\n## Pitfalls\n\n- **The right name, the wrong repository.** A directory named for the project is evidence of\n  nothing — forks, vendored copies and year-old clones all keep the name. The change lands in\n  a copy, every test passes, and the pull request goes to a repository nobody watches.\n- **A base ref nobody has fetched in weeks.** In the session that produced this skill, the\n  located checkout was **228 commits behind** its origin, and looked entirely normal from the\n  inside. Authoring there would have produced a change built on a file two generations old and\n  a pull request that conflicts from its first line — work that reviews as careless and was\n  merely stale.\n- **`git stash` in a shared worktree.** Two agents were working in one tree; one ran\n  `git stash` to get a clean status before committing, and the other agent's **uncommitted**\n  files silently reverted underneath it for about a minute. Nothing errored, nothing warned,\n  and the second agent watched its own edits disappear mid-task. There is no reflog for\n  uncommitted work.\n- **`worktree add` with no base ref.** It succeeds, and branches from whatever HEAD the shared\n  checkout happened to be on — frequently another session's half-finished branch, which then\n  arrives inside your diff as commits you did not write.\n- **Cloning to an invented path.** A second copy appears somewhere the user does not look;\n  later they find two checkouts, cannot tell which one holds the work, and the honest answer\n  requires reading both.\n- **The unnamed destination.** \"Done — 2 commits, tests green\" reads as *here* to anyone in\n  their own terminal. The correction arrives days later, usually from a colleague asking why\n  a branch exists.\n- **The forgotten worktree.** `git branch -d` refuses while a worktree holds the branch, the\n  parent repository keeps an administrative entry pointing at a path that may no longer exist,\n  and the next session inherits a tree whose purpose nobody recorded.\n- **\"Just for a minute\" in the shared checkout.** The minute becomes a commit on the wrong\n  branch, or a dirty tree handed back to whoever was already using it.\n- **A shallow clone.** `--depth` makes the ahead/behind count meaningless and can refuse a\n  `worktree add` from a base older than the truncation — after the branch was promised.\n- **Assuming push access.** Discovered at the push, after the commits exist, when the only\n  choices left are a fork nobody agreed to or a branch that stays local and unannounced.\n\n## Verification\n\n- [ ] The target was stated as a remote — owner and name, or a URL — before any directory was\n      chosen.\n- [ ] The chosen checkout's `origin` remote was read and matches that target; its directory name\n      was not the evidence.\n- [ ] Where zero or several candidates were found, the user chose between what you listed.\n- [ ] Any clone landed at a path the user named or approved, and was not shallow.\n- [ ] `git fetch` ran in this session, and both the ahead and behind counts against the base ref\n      appear in the result — or the fetch failed and the result says the counts are unknown.\n- [ ] The branch was cut from the fetched remote ref, with that ref given explicitly to\n      `worktree add`.\n- [ ] Every edit happened in the dedicated worktree; the shared checkout's working tree is as it\n      was found.\n- [ ] No `git stash`, `git reset`, `git checkout --`, rebase or amend ran outside your own\n      worktree.\n- [ ] Every commit staged only paths named explicitly.\n- [ ] The result names the repository, the branch, the worktree path and the commits by sha.\n- [ ] The worktree was removed and no longer appears in `git worktree list`, or the result says\n      it remains, where, and why.\n- [ ] A reader holding only the final answer can say which repository changed, on which branch,\n      and what is left to do there.\n\nThe work is finished when someone who never saw the session can find it: a named repository, a\nnamed branch, a sha they can check out, and no second tree left behind that nobody can account\nfor.\n","bodyHtml":"<h2 id=\"work-in-an-external-repository\">Work in an external repository</h2>\n<p>The work is wanted somewhere else — another repository, on this machine or not yet on it — and\nevery way that goes wrong is quiet. The agent edits a checkout whose directory has the right\nname and belongs to a fork. It works directly in a checkout another session is holding. It\nbranches off a base ref last fetched in a different month. It clones to a path it invented,\nproducing a second copy nobody will find. And at the end it reports two commits and a green\ntest run without ever naming a repository, so the reader — looking at their own terminal —\nconcludes the work landed here.</p>\n<p>None of these announce themselves. Every command succeeds, the diff looks right, and the\ndamage surfaces in somebody else&#39;s session or in a pull request that conflicts from its first\nline.</p>\n<p>This skill owns the route to the target and the tree the work happens in: establishing which\nrepository is meant, proving the checkout is that repository, getting a current base, working\nsomewhere nobody else is standing, and saying afterwards where the work went. It does <strong>not</strong>\nown the change — <code>land-complex-change</code> contains that. It does not own the description of the\ndiff (<code>describe-changes</code>), the review loop (<code>request-blocks-review</code>), or the shape of a status\nreport (<code>report-progress</code>); it hands that report one line it must carry, which is where the\nwork landed.</p>\n<h4 id=\"what-this-skill-does-not-own\">What this skill does not own</h4>\n<table>\n<thead>\n<tr>\n<th>The job</th>\n<th>Whose it is</th>\n<th>What this skill does with it</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>Containing the change once you are in the right tree</td>\n<td><code>land-complex-change</code></td>\n<td>Hands over a clean worktree at a known base; declares no touch-set of its own.</td>\n</tr>\n<tr>\n<td>Saying what the landed diff did</td>\n<td><code>describe-changes</code></td>\n<td>Calls it after the commits exist, in the worktree it created.</td>\n</tr>\n<tr>\n<td>The review loop over the pull request</td>\n<td><code>request-blocks-review</code></td>\n<td>Hands over the repository, branch and head sha; runs no review of its own.</td>\n</tr>\n<tr>\n<td>The shape of progress reports</td>\n<td><code>report-progress</code></td>\n<td>Supplies the destination line every report of external work owes.</td>\n</tr>\n<tr>\n<td>What the child agents are doing</td>\n<td><code>agent-lifecycle</code></td>\n<td>Consumes it; two agents in one repository is exactly when it is needed.</td>\n</tr>\n</tbody></table>\n<p>Install the companions with <code>npx skills add crissmoldovan/agent-skills</code>.</p>\n<h3 id=\"when-to-use\">When to Use</h3>\n<ul>\n<li>The request names <strong>another repository</strong> — by owner and name, by URL, or by a shorthand only\nthe user can resolve — and the change belongs there rather than here.</li>\n<li>A branch, a commit or a pull request is wanted in a repository that is not this working\ndirectory.</li>\n<li>The target may not be on this machine at all, and a clone is on the table.</li>\n<li>The target <strong>is</strong> on this machine as a checkout a person or another session may be using.</li>\n<li>Two agents are working in one repository at the same time, whatever the task.</li>\n<li>A previous session left a worktree behind and this session continues that work.</li>\n</ul>\n<p>Do not use it for work in the current repository: everything here is overhead you have already\npaid. Do not use it for read-only inspection of another repository — locating a checkout,\nreading its files, running <code>git log</code> in it — that changes nothing and needs no worktree; only\nthe write turns this on. Do not use it as a plan for the change itself; the moment the tree is\nright, <code>land-complex-change</code> takes over and this skill is finished until the result is written.</p>\n<h3 id=\"prerequisites\">Prerequisites</h3>\n<ol>\n<li><strong>The target as a remote, not as a directory.</strong> <code>owner/name</code>, or a clone URL.\n<strong>Complete when:</strong> the target is written down in a form that would identify the same\nrepository on a machine with no local checkouts at all.</li>\n<li><strong>The base ref the work branches from.</strong> <code>main</code> is a guess, not a default; some repositories\nrelease from another branch.\n<strong>Complete when:</strong> the base ref is named, or the user has confirmed the repository&#39;s default.</li>\n<li><strong>Somewhere worktrees may be created.</strong> A parent directory that exists and is not inside the\nshared checkout.\n<strong>Complete when:</strong> the parent path is known and the user approved it if it is new.</li>\n<li><strong>Whether the work may be pushed.</strong> Push access, a fork, or an agreement that this ends at a\nlocal branch.\n<strong>Complete when:</strong> the end state of the branch is agreed before the first commit, not\ndiscovered at the push.</li>\n<li><strong>Knowledge of who else is in there.</strong> Another agent, another session, a person with a dirty\ntree.\n<strong>Complete when:</strong> <code>git -C &lt;repo&gt; worktree list</code> and <code>git -C &lt;repo&gt; status</code> have been read,\nand a dirty shared tree is treated as occupied.</li>\n</ol>\n<h3 id=\"procedure\">Procedure</h3>\n<ol>\n<li><p><strong>Establish the target repository by name, before anything else.</strong> Never assume the current\nrepository is the target — the working directory is where the conversation happens, not\nwhere the work belongs. Resolve the request to <code>owner/name</code> or a URL. If it arrives as &quot;the\nskills repo&quot; or &quot;the API one&quot;, ask which remote that is; do not resolve a nickname against\nthe filesystem and take the first hit.\n<strong>Complete when:</strong> the target is stated as a remote, and nothing has yet been read from a\ndirectory chosen because its name looked right.</p>\n</li>\n<li><p><strong>Locate before creating.</strong> Search the roots repositories live under —\n<code>find &lt;search-root&gt; -maxdepth 3 -type d -name .git</code> — and read\n<code>git -C &lt;candidate&gt; worktree list</code>, which shows checkouts of that repository you would\notherwise clone a second time. Then prove the candidate:\n<code>git -C &lt;candidate&gt; remote get-url origin</code> must equal the target. <strong>A directory with the\nright name is not proof</strong>: forks, vendored copies and abandoned clones all carry the name of\nthe thing they were copied from. If <strong>zero</strong> candidates survive, go to step 3. If <strong>several</strong>\ndo, ask the user which one, listing each candidate&#39;s origin URL and current branch — picking\nthe newest or the shortest path is a guess wearing a decision&#39;s clothes.\n<strong>Complete when:</strong> the chosen path&#39;s <code>origin</code> matches the named target, confirmed before any\nwrite rather than after the first edit; or the user has chosen from candidates you listed.</p>\n</li>\n<li><p><strong>If it is not on this machine, confirm the destination before cloning.</strong> Never invent a\nparent directory, and never clone into the current repository&#39;s tree. Propose a path, get it\nconfirmed, then <code>git clone &lt;url&gt; &lt;path&gt;</code>. Clone fully: a <code>--depth</code> clone makes the ahead/\nbehind count in the next step meaningless and can refuse a <code>worktree add</code> from an old ref.\n<strong>Complete when:</strong> the clone exists at a path the user named or approved, and its <code>origin</code> is\nthe target&#39;s URL.</p>\n</li>\n<li><p><strong>Refresh the base ref and report ahead/behind.</strong> <code>git -C &lt;repo&gt; fetch origin</code>, then\n<code>git -C &lt;repo&gt; rev-list --left-right --count origin/&lt;base&gt;...HEAD</code> — the left number is how\nfar <strong>behind</strong> the local ref is, the right is how far <strong>ahead</strong>. Say both out loud. A stale\nbase is the default state of a checkout nobody has touched, not an exception, and a checkout\nhundreds of commits behind looks exactly like a current one from the inside. If the fetch\nfails, say the ahead/behind is unknown; do not branch blind and call it current.\n<strong>Complete when:</strong> the fetch ran in this session and both counts are stated, or the failure is\nreported in place of them.</p>\n<p>The number is not what makes the branch correct — step 5 branches from the fetched\n<code>origin/&lt;base&gt;</code> regardless, so a stale local ref cannot contaminate it. It is what tells you\nthe shared checkout&#39;s <em>working files</em> are old, which matters the moment you read one to\ndecide what to write, and it predicts whether the eventual pull request opens clean or\narrives hundreds of commits behind its target.</p>\n</li>\n<li><p><strong>Create a dedicated worktree on a new branch, never in the shared checkout.</strong> The form is\n<code>git worktree add -b &lt;branch&gt; &lt;path&gt; &lt;base&gt;</code>, run as\n<code>git -C &lt;repo&gt; worktree add -b feat/&lt;slug&gt; &lt;parent&gt;/&lt;repo&gt;-wt-&lt;slug&gt; origin/&lt;base&gt;</code>. The third\nargument is the base ref and it is not optional: omit it and git silently branches from\nwhatever HEAD the shared checkout is sitting on, which may be another session&#39;s half-finished\nbranch. Work in that new path only. Another session may be using the shared checkout, and its\nbranch, its index and its uncommitted files are not yours to move.\n<strong>Complete when:</strong> the worktree exists outside the shared checkout, <code>git -C &lt;worktree&gt; status</code>\nis clean, and the branch points at the ref fetched in step 4.</p>\n</li>\n<li><p><strong>Keep off the shared tree: the forbidden operations.</strong> In any tree another session or person\nmay be using — including the checkout you located in step 2 — never run <code>git stash</code>,\n<code>git reset</code>, or <code>git checkout --</code>, and never rebase or amend a commit you did not create.\nEach is silent by design: it prints almost nothing, it exits zero, and what it destroys is\nsomebody else&#39;s uncommitted work, which has no reflog to recover it from. Stage by explicit\npath — <code>git -C &lt;worktree&gt; add &lt;path&gt;</code> — never a whole-tree stage, so a file you did not write\ncannot ride along in your commit.\n<strong>Complete when:</strong> every git command run outside your own worktree was read-only, and every\ncommit staged only paths you named.</p>\n</li>\n<li><p><strong>Name the destination in every result.</strong> Repository, branch, worktree path, commits by sha\nand count. A result that does not name the repository invites the reader to assume the\ncurrent one — they are looking at their own terminal, and nothing in your answer contradicts\nthem. This line is owed in intermediate reports too, not only at the end.\n<strong>Complete when:</strong> the answer states repository, branch, worktree path and commits, and a\nreader who never saw a command of yours can tell which repository changed.</p>\n</li>\n<li><p><strong>Clean up, or hand over in writing.</strong> Either remove the tree —\n<code>git -C &lt;repo&gt; worktree remove &lt;path&gt;</code> then <code>git -C &lt;repo&gt; worktree prune</code> — or say in the\nresult that it remains, where it is, and on which branch. A forgotten worktree blocks the\nbranch from being deleted (<code>git branch -d</code> refuses while a worktree holds it), leaves an\nadministrative entry in the parent repository, and hands the next session a second tree whose\npurpose nobody remembers.\n<strong>Complete when:</strong> the worktree is gone from <code>git -C &lt;repo&gt; worktree list</code>, or the result\nnames the path that survives and why it was kept.</p>\n</li>\n</ol>\n<h3 id=\"usage-examples\">Usage Examples</h3>\n<pre><code class=\"language-text\">The change goes in &lt;owner&gt;/&lt;repo&gt;, not in this working directory. Find the checkout if it is on\nthis machine, and confirm it is the right one by its origin remote before you write anything.\nIf you find none, or more than one, tell me what you found and let me pick — do not choose.\n</code></pre>\n<pre><code class=\"language-text\">Before you branch: fetch the base and tell me how far behind that checkout is. If it is more\nthan a handful of commits, I want to hear the number before you build anything on it.\n</code></pre>\n<pre><code class=\"language-text\">Another agent is working in that repository right now. Do your work in a worktree of your own\noff origin/main, and do not run stash, reset or checkout -- anywhere in the shared checkout.\nStage only the paths you actually wrote.\n</code></pre>\n<pre><code class=\"language-text\">When you are done, tell me which repository and branch the commits are on, the worktree path,\nand whether you removed it. &quot;Done, 2 commits&quot; tells me nothing about where they are.\n</code></pre>\n<h4 id=\"the-sequence-end-to-end\">The sequence, end to end</h4>\n<pre><code class=\"language-bash\"># 1. Locate, then prove it — a matching directory name is not proof of anything.\nfind &lt;search-root&gt; -maxdepth 3 -type d -name .git\ngit -C &lt;candidate&gt; remote get-url origin       # must equal the named target\ngit -C &lt;candidate&gt; worktree list               # what is already checked out, and where\n\n# 2. Refresh the base. Left = commits you are behind; right = commits you are ahead.\ngit -C &lt;candidate&gt; fetch origin\ngit -C &lt;candidate&gt; rev-list --left-right --count origin/main...HEAD\n\n# 3. Branch into a tree of your own, off the ref you just fetched.\ngit -C &lt;candidate&gt; worktree add -b feat/&lt;slug&gt; &lt;parent&gt;/&lt;repo&gt;-wt-&lt;slug&gt; origin/main\n\n# 4. Work there, staging by explicit path only.\ngit -C &lt;parent&gt;/&lt;repo&gt;-wt-&lt;slug&gt; add &lt;path&gt;\ngit -C &lt;parent&gt;/&lt;repo&gt;-wt-&lt;slug&gt; commit -F &lt;message-file&gt;\n\n# 5. Hand back: remove the tree, or say in the result that it remains.\ngit -C &lt;candidate&gt; worktree remove &lt;parent&gt;/&lt;repo&gt;-wt-&lt;slug&gt;\ngit -C &lt;candidate&gt; worktree prune\n</code></pre>\n<h3 id=\"what-it-looks-like\">What it looks like</h3>\n<p>A specimen, not a prompt. This is what the result should say when the work is\ndone and handed back.</p>\n<h4 id=\"a-result-that-names-where-the-work-landed\">A result that names where the work landed</h4>\n<pre><code class=\"language-text\">Repository: &lt;owner&gt;/&lt;repo&gt; — origin git@github.com:&lt;owner&gt;/&lt;repo&gt;.git. Not this working\ndirectory; nothing here changed.\nBranch: feat/&lt;slug&gt;, cut from origin/main at a1b2c3d, fetched in this session (0 behind).\nWorktree: &lt;parent&gt;/&lt;repo&gt;-wt-&lt;slug&gt; — still present, deliberately, for the review pass.\nCommits: 2 — 4d1f0c7, 9e8a210. Pushed to origin/feat/&lt;slug&gt;; no pull request opened.\n</code></pre>\n<p>Every line of it is checkable by someone who saw none of the session: the repository is named\nas a remote rather than as a path, the base carries the sha it was cut from and the freshness\nof that ref, the worktree&#39;s survival is stated rather than left to be discovered, and the\ncommits are countable.</p>\n<h3 id=\"pitfalls\">Pitfalls</h3>\n<ul>\n<li><strong>The right name, the wrong repository.</strong> A directory named for the project is evidence of\nnothing — forks, vendored copies and year-old clones all keep the name. The change lands in\na copy, every test passes, and the pull request goes to a repository nobody watches.</li>\n<li><strong>A base ref nobody has fetched in weeks.</strong> In the session that produced this skill, the\nlocated checkout was <strong>228 commits behind</strong> its origin, and looked entirely normal from the\ninside. Authoring there would have produced a change built on a file two generations old and\na pull request that conflicts from its first line — work that reviews as careless and was\nmerely stale.</li>\n<li><strong><code>git stash</code> in a shared worktree.</strong> Two agents were working in one tree; one ran\n<code>git stash</code> to get a clean status before committing, and the other agent&#39;s <strong>uncommitted</strong>\nfiles silently reverted underneath it for about a minute. Nothing errored, nothing warned,\nand the second agent watched its own edits disappear mid-task. There is no reflog for\nuncommitted work.</li>\n<li><strong><code>worktree add</code> with no base ref.</strong> It succeeds, and branches from whatever HEAD the shared\ncheckout happened to be on — frequently another session&#39;s half-finished branch, which then\narrives inside your diff as commits you did not write.</li>\n<li><strong>Cloning to an invented path.</strong> A second copy appears somewhere the user does not look;\nlater they find two checkouts, cannot tell which one holds the work, and the honest answer\nrequires reading both.</li>\n<li><strong>The unnamed destination.</strong> &quot;Done — 2 commits, tests green&quot; reads as <em>here</em> to anyone in\ntheir own terminal. The correction arrives days later, usually from a colleague asking why\na branch exists.</li>\n<li><strong>The forgotten worktree.</strong> <code>git branch -d</code> refuses while a worktree holds the branch, the\nparent repository keeps an administrative entry pointing at a path that may no longer exist,\nand the next session inherits a tree whose purpose nobody recorded.</li>\n<li><strong>&quot;Just for a minute&quot; in the shared checkout.</strong> The minute becomes a commit on the wrong\nbranch, or a dirty tree handed back to whoever was already using it.</li>\n<li><strong>A shallow clone.</strong> <code>--depth</code> makes the ahead/behind count meaningless and can refuse a\n<code>worktree add</code> from a base older than the truncation — after the branch was promised.</li>\n<li><strong>Assuming push access.</strong> Discovered at the push, after the commits exist, when the only\nchoices left are a fork nobody agreed to or a branch that stays local and unannounced.</li>\n</ul>\n<h3 id=\"verification\">Verification</h3>\n<ul>\n<li><input disabled=\"\" type=\"checkbox\"> The target was stated as a remote — owner and name, or a URL — before any directory was\nchosen.</li>\n<li><input disabled=\"\" type=\"checkbox\"> The chosen checkout&#39;s <code>origin</code> remote was read and matches that target; its directory name\nwas not the evidence.</li>\n<li><input disabled=\"\" type=\"checkbox\"> Where zero or several candidates were found, the user chose between what you listed.</li>\n<li><input disabled=\"\" type=\"checkbox\"> Any clone landed at a path the user named or approved, and was not shallow.</li>\n<li><input disabled=\"\" type=\"checkbox\"> <code>git fetch</code> ran in this session, and both the ahead and behind counts against the base ref\nappear in the result — or the fetch failed and the result says the counts are unknown.</li>\n<li><input disabled=\"\" type=\"checkbox\"> The branch was cut from the fetched remote ref, with that ref given explicitly to\n<code>worktree add</code>.</li>\n<li><input disabled=\"\" type=\"checkbox\"> Every edit happened in the dedicated worktree; the shared checkout&#39;s working tree is as it\nwas found.</li>\n<li><input disabled=\"\" type=\"checkbox\"> No <code>git stash</code>, <code>git reset</code>, <code>git checkout --</code>, rebase or amend ran outside your own\nworktree.</li>\n<li><input disabled=\"\" type=\"checkbox\"> Every commit staged only paths named explicitly.</li>\n<li><input disabled=\"\" type=\"checkbox\"> The result names the repository, the branch, the worktree path and the commits by sha.</li>\n<li><input disabled=\"\" type=\"checkbox\"> The worktree was removed and no longer appears in <code>git worktree list</code>, or the result says\nit remains, where, and why.</li>\n<li><input disabled=\"\" type=\"checkbox\"> A reader holding only the final answer can say which repository changed, on which branch,\nand what is left to do there.</li>\n</ul>\n<p>The work is finished when someone who never saw the session can find it: a named repository, a\nnamed branch, a sha they can check out, and no second tree left behind that nobody can account\nfor.</p>\n","outline":["When to Use","Prerequisites","Procedure","Usage Examples","What it looks like","Pitfalls","Verification"],"words":2911}
