$npx -y skills add aaddrick/claude-pipeline --skill using-git-worktreesUse when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees in .worktrees/
| 1 | # Using Git Worktrees |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching. |
| 6 | |
| 7 | **Location:** Always use `.worktrees/` (per CLAUDE.md) |
| 8 | |
| 9 | **Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace." |
| 10 | |
| 11 | ## Safety Verification |
| 12 | |
| 13 | **Verify `.worktrees/` is ignored before creating worktree:** |
| 14 | |
| 15 | ```bash |
| 16 | git check-ignore -q .worktrees 2>/dev/null |
| 17 | ``` |
| 18 | |
| 19 | **If NOT ignored:** Add to .gitignore and commit before proceeding. |
| 20 | |
| 21 | **Why critical:** Prevents accidentally committing worktree contents to repository. |
| 22 | |
| 23 | ## Creation Steps |
| 24 | |
| 25 | ### 1. Create Worktree |
| 26 | |
| 27 | ```bash |
| 28 | git worktree add .worktrees/$BRANCH_NAME -b $BRANCH_NAME $BASE_BRANCH |
| 29 | cd .worktrees/$BRANCH_NAME |
| 30 | ``` |
| 31 | |
| 32 | ### 2. Run Project Setup |
| 33 | |
| 34 | **Laravel:** |
| 35 | |
| 36 | Fresh worktrees don't have `vendor/` or `node_modules/`. Install dependencies first: |
| 37 | |
| 38 | ```bash |
| 39 | # 1. Create bootstrap/cache (required for composer) |
| 40 | mkdir -p bootstrap/cache |
| 41 | |
| 42 | # 2. Install PHP dependencies |
| 43 | composer install --no-interaction |
| 44 | |
| 45 | # 3. Run Laravel setup (migrations, seeds, caches) |
| 46 | php artisan migrate --seed |
| 47 | |
| 48 | # 4. Build frontend assets (Vite manifest required for tests) |
| 49 | npm install && npm run build |
| 50 | ``` |
| 51 | |
| 52 | **Why this order matters:** |
| 53 | - `bootstrap/cache` must exist before composer runs post-install scripts |
| 54 | - `vendor/` must exist before artisan commands work |
| 55 | - Vite manifest must exist or tests using views will fail |
| 56 | |
| 57 | **Other projects:** Auto-detect from project files: |
| 58 | ```bash |
| 59 | if [ -f package.json ]; then npm install; fi |
| 60 | if [ -f Cargo.toml ]; then cargo build; fi |
| 61 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
| 62 | if [ -f pyproject.toml ]; then poetry install; fi |
| 63 | if [ -f go.mod ]; then go mod download; fi |
| 64 | ``` |
| 65 | |
| 66 | ### 3. Verify Baseline |
| 67 | |
| 68 | Run tests to ensure worktree starts clean: |
| 69 | ```bash |
| 70 | # Laravel |
| 71 | php artisan test |
| 72 | |
| 73 | # Other |
| 74 | npm test / cargo test / pytest / go test ./... |
| 75 | ``` |
| 76 | |
| 77 | **If tests fail:** Verify setup completed correctly (vendor/, node_modules/, Vite manifest all exist). Compare with main worktree to identify if failures are pre-existing. |
| 78 | |
| 79 | **If tests pass:** Report ready. |
| 80 | |
| 81 | ### 4. Report Location |
| 82 | |
| 83 | ``` |
| 84 | Worktree ready at <full-path> |
| 85 | Branch: <branch-name> |
| 86 | Tests: <N> passed (<M> pre-existing failures if any) |
| 87 | Ready to implement <feature-name> |
| 88 | ``` |
| 89 | |
| 90 | ## Quick Reference |
| 91 | |
| 92 | | Situation | Action | |
| 93 | |-----------|--------| |
| 94 | | Creating worktree | `git worktree add .worktrees/$BRANCH -b $BRANCH $BASE` | |
| 95 | | `.worktrees/` not ignored | Add to .gitignore + commit first | |
| 96 | | Laravel project | `mkdir -p bootstrap/cache` → `composer install` → `php artisan migrate --seed` → `npm install && npm run build` | |
| 97 | | Other projects | Auto-detect from package.json, Cargo.toml, etc. | |
| 98 | | Tests fail during baseline | Verify setup complete (vendor/, node_modules/, Vite manifest), compare with main | |
| 99 | |
| 100 | ## Common Mistakes |
| 101 | |
| 102 | ### Skipping ignore verification |
| 103 | |
| 104 | - **Problem:** Worktree contents get tracked, pollute git status |
| 105 | - **Fix:** Always use `git check-ignore` before creating worktree |
| 106 | |
| 107 | ### Running artisan commands before composer install |
| 108 | |
| 109 | - **Problem:** Fresh worktrees have no `vendor/` directory - artisan commands fail |
| 110 | - **Fix:** Run `composer install` first, then artisan commands |
| 111 | |
| 112 | ### Missing bootstrap/cache directory |
| 113 | |
| 114 | - **Problem:** Composer post-install scripts fail with "directory must be present and writable" |
| 115 | - **Fix:** Create `mkdir -p bootstrap/cache` before running `composer install` |
| 116 | |
| 117 | ### Skipping npm build |
| 118 | |
| 119 | - **Problem:** Tests that render views fail with "Vite manifest not found" |
| 120 | - **Fix:** Run `npm install && npm run build` after Laravel setup |
| 121 | |
| 122 | ### Hardcoding setup commands |
| 123 | |
| 124 | - **Problem:** Breaks on projects using different tools |
| 125 | - **Fix:** Use documented sequence for Laravel, auto-detect for others |
| 126 | |
| 127 | ## Example Workflow |
| 128 | |
| 129 | ``` |
| 130 | You: I'm using the using-git-worktrees skill to set up an isolated workspace. |
| 131 | |
| 132 | [Verify ignored: git check-ignore .worktrees - confirmed] |
| 133 | [Create worktree: git worktree add .worktrees/issue-123 -b issue-123-feature aw-next] |
| 134 | [mkdir -p bootstrap/cache] |
| 135 | [composer install --no-interaction] |
| 136 | [php artisan migrate --seed] |
| 137 | [npm install && npm run build] |
| 138 | [php artisan test - all tests passed] |
| 139 | |
| 140 | Worktree ready at /home/user/project/.worktrees/issue-123 |
| 141 | Branch: issue-123-feature |
| 142 | Tests: 639 passed (0 failures) |
| 143 | Ready to implement feature |
| 144 | ``` |
| 145 | |
| 146 | ## Red Flags |
| 147 | |
| 148 | **Never:** |
| 149 | - Create worktree without verifying `.worktrees/` is ignored |
| 150 | - Run artisan commands before `composer install` in fresh worktree |
| 151 | - Skip `npm run build` - tests will fail on missing Vite manifest |
| 152 | |
| 153 | **Always:** |
| 154 | - Use `.worktrees/` directory |
| 155 | - Verify directory is ignored |
| 156 | - Create `bootstrap/cache` before composer install |
| 157 | - Follow setup order: composer → artisan migrate → npm build |
| 158 | |
| 159 | ## Integration |
| 160 | |
| 161 | **Called by:** |
| 162 | - **brainstorming** (Phase 4) - when d |