# Consolidating many parallel worktrees back into main Use this recipe at the end of a session that ran several isolated git worktrees in parallel (one per feature/fix, dispatched to web/image/ mobile specialist workers) and now needs everything merged into one shared branch. ## 1. Sweep every worktree before merging any of them For each worktree, in order: ``` cd git status --short ``` A worker reporting `exit 0` or a finished task is NOT proof the work is committed (see main SKILL.md rule 30) — it is common for several worktrees in a batch to have real, finished, uncommitted changes sitting in the working tree because the worker ran out of turns right before its own commit step. Treat `git status --short` as the source of truth, not the worker's report. For every worktree with uncommitted changes: review the diff briefly, drop any unrelated pre-existing changes (e.g. a stray `package-lock.json` touch from an earlier unrelated run) from the commit, then commit with a message describing what the branch actually contains. Do this for ALL worktrees first, before starting any merge — merging while a sibling worktree still has uncommitted work risks losing that work if you later decide the branch is clean and move on. ## 2. Merge one branch at a time, build-verify after each ``` cd git merge --no-edit npm run build # or the project's equivalent — do this immediately, not after all merges git merge --no-edit npm run build ... repeat ... ``` Merging sequentially with an immediate build after each merge isolates which merge introduced a problem; merging all branches first and building once at the end makes a failure much harder to bisect. ## 3. Resolve conflicts by combining intent, not by blindly picking a side Two real conflict shapes that come up often in this kind of batch: - **Same-name top-level declaration added independently by two branches** (e.g. two branches each add `const CUSTOM_PAGES = {...}` with different keys because neither saw the other's work). Do not `git checkout --ours`/ `--theirs` blindly — read both definitions, understand what each key is *for*, and write one combined declaration that preserves every entry. Then grep the file for any other reference to the removed duplicate to make sure nothing still points at the deleted one. - **A genuinely superseding change** (e.g. one branch did a full visual redesign of a file another branch also touched). Here taking one side wholesale (`git checkout --theirs `) is correct — but always rebuild and smoke-check afterward; the "losing" side's small unrelated fixes in the same file are now gone and may need to be re-applied by hand if they still matter. ## 4. Grep for stray conflict markers after every "clean" merge A `git merge` that reports success for a file can still leave a trailing marker behind when conflict context extends past what a patch-based review tool showed you (common at the very end of a CSS/JS file). Before trusting a merge: ``` grep -n "^<<<<<<<\|^=======$\|^>>>>>>>" ``` A build can even succeed with a stray marker still present (e.g. a CSS minifier emitting a `css-syntax-error` warning but still producing output) — read the full build output, not just the exit code, and treat any minifier warning introduced by the merge as a signal to go check for a leftover marker. ## 5. A worktree is safe to hand a NEW task only once its current worker has exited Reusing the same worktree/branch for a v2/v3 follow-up task (sequentially, after the first task's work is committed) is fine and often the right call — it keeps related history together. Spawning a *second concurrent* worker in that same worktree while the first is still running is the thing rule 19 forbids; check `ps aux` for the task file path before reusing a worktree.