references/worktree.md
about 750 tokens- greenline
# A worktree of its own
Frame reads this page when the change's ground is a worktree of its own, on the owner's word at the proposal or by the workspace's standing choice. A worktree is a second checkout of the repository on the change's own branch: the change's edits, its checks and its commits go there, and the main checkout stays as the owner left it. Make it in this order once the owner has answered, and never ask the ground's question a second time here.
1. **Detect it first.** A session that already runs in a linked worktree makes none: that worktree is the ground. In a linked worktree `git rev-parse --git-dir` and `git rev-parse --git-common-dir` name different directories; they differ in a submodule too, so a git directory under the common one's `modules/` is a submodule, not a worktree. On a detached HEAD there, name no branch and ask.
2. **Use the harness's own tool.** Where the harness gives the session a tool that makes a worktree, make it with that tool, never with git beside it: a worktree git makes behind the harness's back is state the harness cannot see or clean up. Otherwise use git, below.
3. **Choose the directory.** The directory the repository's own instructions name for worktrees, else an existing `.worktrees/` or `worktrees/` at the root, else `.worktrees/` at the root, the worktree at `<directory>/<id>` under the change's id. Before making it, have git ignore the directory through the repository's local exclude file, the path `git rev-parse --git-path info/exclude` gives, never by a line committed to `.gitignore`: no change is open yet to commit it, and an unignored directory shows in the main checkout as untracked work.
4. **Make it on the change's branch.** `git worktree add <directory>/<id> -b greenline/<id> <default branch>` makes the branch from the default branch and checks it out there. From then on every command of the change runs in the worktree; where the session itself stays in the main checkout, name the worktree in each command's own words, `cd <directory>/<id> && <command>`, since a harness may hand its hooks no directory for a command and they read its paths from the session's.
5. **Set the project up.** Run the project's own setup in the worktree, the install or bootstrap command its documents or its manifest name: a fresh checkout holds no dependencies and no built files.
6. **Take a clean baseline.** Once the record is open, run the project's test command in the worktree before the first edit of its code, recorded as a check. A red baseline goes to the owner with what failed, and the owner decides whether the work starts on it, so a later failure is never blamed on the change.
7. **On a refusal, offer the branch.** Where the harness or a sandbox refuses the worktree, say so, offer the branch of its own in place, the other ground, and wait for the owner's word.
The worktree leaves at the landing, on the owner's word, once its work is committed; a worktree that holds uncommitted work is never removed.