# Git and worktrees This file says how sessions handle branches, worktrees, unrelated diffs and setup. The pstack block in `AGENTS.md` points here. The `sync-pstack` skill renders this file from its shared source in `udecode/ustack`, so change it there. - **Git.** Before a nontrivial edit, check only `git branch --show-current`. Never edit from `main`. This clone's `origin/HEAD` points at `origin/next`, because the desktop app cuts new worktrees from it. `git remote set-head origin --auto` follows the remote's default, which need not be `next`, so never run it. Before a session gets its own worktree, a suggested task's card included, the lead runs `node .agents/pstack/head.mjs`, which points `origin/HEAD` back at `origin/next` when it has moved. Ignore unrelated diffs and never pause to ask about them. Never reset or discard work this run did not write. Reset a proof case in a fresh detached worktree; never run `git stash` in this repository or any of its worktrees, because every worktree shares one stash list. Remove only a worktree the run created other than its own, or one the `cleanup` skill marks safe; a session leaves its own for the cleanup scan, which removes it after a quiet day. Remove it with `git worktree remove --force ` and confirm with `git worktree list`; never run `git worktree prune`, which edits the worktree registry every checkout shares. Before anything runs in a worktree of this repository the run adds for a proof or a seat, run `node .agents/pstack/setup.mjs` from inside it, with each `--install` and `--env` value the project's `SessionStart` hook passes that script, quoted as the hook quotes it, and without `--hook` or the hook's `cd`. It copies the main checkout's env files and installs dependencies. When it exits 1, fix the install before anything else runs there. A project helper that makes and sets up its own worktree replaces this step.