skills/git-worktree-workflows/SKILL.md
Use the `gw` CLI for ALL Git worktree work — creating, navigating, listing, removing, syncing, updating, checking out PRs, troubleshooting. Replaces raw `git worktree`, `cd ../wt`, `git checkout -b`, and manual file copies. Triggers on: "spin up a branch", "work on a feature", "check out PR", "switch branch without stashing", "create a worktree", "parallel branches", "clean up branches", "gw", "gw add", "gw checkout", "git worktree", or any branch workflow.
npx skillsauth add mthines/gw-tools git-worktree-workflowsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Master Git worktrees using the gw CLI tool for optimized parallel development workflows.
gw, Never Raw git worktreeNon-negotiable in any repo where gw is installed. Check with which gw; if missing, suggest brew install mthines/gw-tools/gw or npm install -g @gw-tools/gw.
| Instead of | Use | Why it matters |
| ---------------------------------------------- | -------------------------------------- | ----------------------------------------------------------- |
| git worktree add ../feat feat | gw checkout feat | Auto-copies files, runs hooks, remote probe, auto-cd |
| git worktree remove feat | gw remove feat | Prunes orphan branch, protects main |
| git checkout -b feat | gw checkout feat | Isolated worktree instead of in-place branch switch |
| git checkout main (when main is another wt) | gw checkout main | Detects existing worktree and navigates instead of erroring |
| cd ../feat | gw cd feat | Partial matching, works from any depth |
| git fetch && git checkout pr-branch | gw pr <number> | Handles fork PRs, auto-copies, runs hooks |
| Manually cp ../main/.env .env after worktree | Configure autoCopyFiles in gw init | One-time setup, auto-copies forever after |
| Rule | Description |
| --------------------------------------------- | ---------------------------------------------------------------------------------------- |
| fundamentals | HIGH - Core concepts of Git worktrees, what they share/don't share, when to use them |
| creation | HIGH - Creating worktrees with gw checkout, remote fetch behavior, auto-copy files |
| navigation | MEDIUM - Navigating with gw cd and gw checkout, shell integration setup |
| inspection | LOW - Listing worktrees with gw list, understanding worktree states |
| cleanup | MEDIUM - Removing worktrees, gw clean, gw prune, disk space management |
| troubleshooting | HIGH - Common errors and solutions, recovery procedures |
| Pattern | Description |
| -------------------------------------------------------- | ------------------------------------------------------------- |
| feature-branch | HIGH - Feature development workflow with worktrees |
| hotfix | HIGH - Urgent bug fixes without interrupting feature work |
| code-review | HIGH - Review PRs in isolated environments with gw pr |
| parallel-testing | MEDIUM - Test across Node versions or configurations |
| Task | Command |
| ----------------------------------------- | ------------------------------------------------------------------- |
| Create worktree (new branch) | gw checkout feat/name |
| Create worktree (alias) | gw co feat/name or gw add feat/name |
| Create from different branch | gw checkout feat/name --from develop |
| Create from staged files (extract WIP) | gw checkout feat/name --from-staged |
| Create without auto-navigation | gw checkout feat/name --no-cd |
| Skip remote probe (offline mode) | gw checkout feat/name --no-fetch |
| Navigate to worktree by name | gw cd feat/name |
| Navigate by partial match | gw cd feat (matches first worktree with "feat") |
| Navigate to branch (even if in other wt) | gw checkout main |
| List all worktrees | gw list |
| Check out a PR into a worktree | gw pr 123 |
| Check out a PR by URL | gw pr https://github.com/user/repo/pull/123 |
| Update with main (merge or rebase) | gw update |
| Update from specific branch | gw update --from develop |
| Sync auto-copy files to current worktree | gw sync |
| Sync specific files | gw sync .env .env.local |
| Remove worktree + delete local branch | gw remove feat/name |
| Remove worktree but keep branch | gw remove feat/name --preserve-branch |
| Remove multiple worktrees by name | gw remove feat-a feat-b feat-c |
| Remove every worktree under a scope | gw remove feat/* (with shell integration) or gw remove 'feat/*' |
| Remove every worktree starting with name | gw remove fix* (greedy across /) |
| Preview a destructive gw remove | gw remove --dry-run feat/* |
| Batch remove safe (committed, pushed) wts | gw clean |
| Preview batch cleanup | gw clean --dry-run |
| Full cleanup: worktrees + orphan branches | gw prune |
| Get repo root path (worktree-aware) | gw root |
| Task | Command |
| --------------------------------------------- | --------------------------------------------------------------- |
| Clone repo and configure gw (interactive) | gw init [email protected]:user/repo.git --interactive |
| Init gw in existing repo | gw init --auto-copy-files .env --post-checkout "pnpm install" |
| Show current gw config | gw show-init |
| Install shell integration (required for cd) | eval "$(gw install-shell)" (add to ~/.zshrc) |
| Remove shell integration | gw install-shell --remove |
git worktree)| Task | Command |
| -------------------- | ---------------------------- |
| Lock worktree | gw lock feat/name |
| Unlock worktree | gw unlock feat/name |
| Repair worktree | gw repair |
| Move worktree | gw move feat/name new-path |
| Prune stale metadata | gw prune --stale-only |
gw checkout is canonical. gw add and gw co are aliases — prefer gw checkout in explanations.gw checkout <existing> detects this and navigates instead.gw checkout runs git ls-remote (3s timeout) so a teammate's freshly-pushed branch isn't silently forked locally. Use --no-fetch when offline.autoCopyFiles once in gw init; .env, secrets, etc. land in every new worktree.pnpm install / equivalent so each worktree is ready immediately.cd. Without eval "$(gw install-shell)" in ~/.zshrc, gw cd and auto-nav after gw checkout silently no-op.# 1. First-time repo setup (one-time per project)
gw init [email protected]:org/repo.git \
--auto-copy-files .env,.env.local \
--post-checkout "pnpm install" \
--interactive
# 2. Start a feature
gw checkout feat/my-feature
# - creates worktree, copies .env, runs pnpm install, auto-navigates
# 3. Work, then update with main
gw update
# 4. Open a PR for review (in another terminal / worktree)
gw pr 456
# - fetches PR branch, creates worktree, copies .env, auto-navigates
# 5. Navigate between worktrees
gw cd feat/my-feature
gw checkout main # navigates to main worktree (already checked out)
# 6. Extract staged WIP to a new branch
git add src/new-thing.ts
gw checkout feat/extracted --from-staged
# 7. Clean up when done
gw remove feat/my-feature # removes worktree + local branch
gw clean # batch remove safe (committed + pushed) worktrees
gw prune # full cleanup: worktrees + orphan branches
Config lives at .gw/config.json (committable) and .gw/config.local.json (gitignored, personal overrides):
{
"defaultBranch": "main",
"autoCopyFiles": [".env", ".env.local", "secrets/"],
"hooks": {
"checkout": {
"pre": ["echo 'Creating: {worktree}'"],
"post": ["pnpm install"],
},
},
"cleanThreshold": 7, // days before worktrees are "stale" for gw clean
"autoClean": true, // silently prune stale worktrees on gw checkout / gw list
"updateStrategy": "merge", // "merge" | "rebase"
}
Hook variables: {worktree}, {worktreePath}, {gitRoot}, {branch}.
mthines/agent-skills)tools
Configure .gw/config.json for gw-tools repos — auto-copy files, hooks, cleanup thresholds, update strategy, and the config migration system. Use when: setting up gw for a new project, adding or changing a config field, adding a hook, configuring auto-copy patterns, asking what fields gw config supports, running gw init, adding a migration, bumping configVersion, keeping schema.json in sync, or troubleshooting missing env files in worktrees.
development
Autonomous feature development workflow using isolated worktrees. Use to autonomously implement features from task description through tested PR delivery. Handles worktree creation, implementation, testing, iteration, documentation, and PR creation. Triggers on autonomous feature development, end-to-end implementation, or "implement X autonomously."
development
Generate a walkthrough artifact (walkthrough.md) summarizing completed work for PR delivery. Gathers information from plan.md, git history, and test results to produce a comprehensive summary. Use at Phase 6 before creating the draft PR. Triggers on create walkthrough, generate walkthrough, write walkthrough artifact.
documentation
Create a comprehensive implementation plan artifact (plan.md) from the current conversation context. Captures all Phase 0-1 discussion into a structured, self-contained document that enables context recovery and session handoff. Use after planning is complete and confidence gate passes. Triggers on create plan, generate plan, write plan artifact.