Worktrees

From projectbluefin/bluefin · View interactive version

Worktrees is an AI agent skill from the GitHub repository projectbluefin/bluefin. Covers the worktree helper script, branch naming, and cleanup so the main checkout stays clean. Use before starting any change, or when the main checkout is dirty or on a stale branch.

How to use this skill

Skill file

Worktrees

Use when

task's work in progress.

sessions cannot collide in the same working tree.

Do not use when

[[ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ]] && echo "already isolated"

The contract

The main checkout at the repository root stays on testing or main with a

clean tree. All feature work happens in .worktrees/<slug>, branched from

projectbluefin/testing.

Two mechanisms enforce this:

and silently corrupts history, so it must never be tracked.

and refuses any remote outside the projectbluefin org.

Install it once after cloning with bash .github/scripts/install-hooks.sh.

Procedure

Create a worktree. The branch is always cut from a freshly fetched

projectbluefin/testing, never from whatever the main checkout happens to be

sitting on:

bash .github/scripts/worktree.sh new fix/my-thing
cd .worktrees/fix-my-thing

Work, validate, and push from inside the worktree:

just check && pre-commit run --all-files
git push projectbluefin fix/my-thing

Clean up after the PR merges:

bash .github/scripts/worktree.sh done fix/my-thing

Housekeeping

List every worktree with its PR state:

bash .github/scripts/worktree.sh list

Remove all worktrees whose PRs are merged or closed. Dirty worktrees are

skipped, never discarded:

bash .github/scripts/worktree.sh prune

Squash merges leave no ancestry, so git branch --merged cannot tell you

whether a branch is finished. worktree.sh asks the forge via gh instead.

Failure modes

| Symptom | Cause | Fix |

|---|---|---|

| pre-push rejects a feature branch | Pushing from the main checkout | Move the work into a worktree, or SKIP_WORKTREE_GUARD=1 for a one-off |

| worktree already exists | Stale directory from earlier work | worktree.sh done <branch>, or git worktree prune if the directory is already gone |

| Untracked .worktrees/ in git status | Hook and ignore rules predate this setup | Confirm .worktrees/ is in .gitignore |

| Uncommitted work blocks done | Real changes in the worktree | Commit them, or git worktree remove <path> --force to discard |

| Unpushed commits block done / prune | Branch has commits not pushed to remote | Push them, use worktree.sh done --force <branch>, or override with SKIP_UNPUSHED_GUARD=1 |

| A repo script reports zero files | It filters .worktrees out by path and is running inside one | Run it from the main checkout, or fix the filter to be checkout-relative |

| gh pr merge --delete-branch fails locally after merging | The branch is still checked out in a worktree | The remote merge succeeded; finish with worktree.sh done <branch> |

Tooling that excludes .worktrees/ by absolute path components silently matches

everything when it runs from inside a worktree. A validator that passes with a

zero-file count is failing, not succeeding — check the count, not the exit code.

Never use git add -A or git add .. Stage explicit paths, then verify with

git status and git diff --cached --name-only before committing.

Red Flags

Verification

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.