laravel-herd-worktrees
Skill3 starsChanged 2 months agoMITView on GitHub
Create, list, or remove git worktrees for Laravel projects served by Laravel Herd on macOS. Use when the user needs a branch worktree, .test URL, or per-worktree PHP/composer isolation.
- Reads credentials
In this repository48 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- architecture-satisfactionSkill
- autopilotSkill
- browser-testSkill
- chatter-scoutSkill
- codebase-designSkill
- code-reviewSkill
- code-smells-auditSkill
- commitSkill
- dependency-auditSkill
- diagnosing-bugsSkill
- distill-sessionsSkill
- domain-modelingSkill
- fix-ci-failuresSkill
- fix-github-issuesSkill
- fix-nightwatch-issuesSkill
- fix-posthog-issuesSkill
- grillingSkill
- grill-meSkill
- grill-with-docsSkill
- handoffSkill
- housekeeperSkill
- implementSkill
- improve-codebase-architectureSkill
- panelSkill
- prototypeSkill
- releaseSkill
- repository-cleanupSkill
- researchSkill
- resolve-review-commentsSkill
- resolving-merge-conflictsSkill
- scratch-cleanupSkill
- scratch-statusSkill
- setupSkill
- tddSkill
- teachSkill
- to-questionnaireSkill
- to-specSkill
- to-ticketsSkill
- triage-github-prSkill
- triageSkill
- verifySkill
- wait-whatSkill
- wayfinderSkill
- which-skillSkill
- wizardSkill
- writing-for-agentsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 9
Run multiple branches of a Laravel project in parallel, each reachable at its own *.test URL through Laravel Herd, with isolated …
- Very specific: line 43
If parking the parent is not desired (other non-Laravel dirs live there), use explicit herd link per worktree instead: see …
- Very specific: line 47
Use the helper script. It creates the worktree, copies .env, rewrites APP_URL + DB_DATABASE + cache prefixes, installs deps, generates app …
- Very specific: line 110
Running
composer installagainst a stalecomposer.lock: after rebasing: always re-run install after switching base branches inside a … - Very specific: line 123
If a .test URL 404s: check herd parked includes the parent, dir name is lowercase, and php artisan route:list works inside the worktree.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Laravel Herd + Git Worktrees
Run multiple branches of a Laravel project in parallel, each reachable at its own *.test URL through Laravel Herd, with isolated dependencies, env, database, and caches.
Mental Model
- A worktree is a sibling directory of the main checkout with its own
HEAD. Composer/Node deps,vendor/,node_modules/,storage/, andbootstrap/cache/are per-worktree: never share via symlink. - Herd's parked directory auto-serves every immediate subdirectory as
<dir>.test. Park the parent of all worktrees once and every new worktree gets a URL for free. .envis untracked, so it must be re-created in each worktree.APP_URL,DB_DATABASE, cache prefixes must differ per worktree to prevent cross-branch bleed.
When to Use This Skill
- User asks to create a worktree for a Laravel app served by Herd.
- User reports
vendor/, migrations, cache, or.envproblems after switching worktrees. - User wants per-branch URL like
myapp-feat.testwithout manual Nginx/Valet config. - User wants the same Laravel project on multiple PHP versions simultaneously.
Workflow
1. One-time setup
Park the parent directory that holds the main checkout (worktrees become siblings of the main checkout, so they land in the same parked dir):
cd ~/Code # parent of your laravel project
herd parkVerify:
herd parkedEach immediate subdir is now <name>.test. Adding a worktree at ~/Code/myapp-feat makes myapp-feat.test resolve immediately.
If parking the parent is not desired (other non-Laravel dirs live there), use explicit herd link per worktree instead: see references/herd-commands.md.
2. Create a new worktree
Use the helper script. It creates the worktree, copies .env, rewrites APP_URL + DB_DATABASE + cache prefixes, installs deps, generates app key, and runs migrations.
bash scripts/worktree-new.sh <branch-suffix> <base-branch> [--driver sqlite|mysql|pgsql]Example:
bash scripts/worktree-new.sh feat-billing main --driver sqliteResult: ../myapp-feat-billing/ exists, myapp-feat-billing.test works, isolated DB.
See scripts/worktree-new.sh for the exact transformations applied to .env.
3. Remove a worktree
bash scripts/worktree-rm.sh <branch-suffix> [--drop-db]Runs git worktree remove, optionally drops the per-worktree DB, and herd unlinks if a manual link exists.
4. Switch PHP version per worktree (optional)
cd ../myapp-legacy
herd isolate php@8.1Site uses 8.1; sibling worktrees keep their isolated or default version. herd isolated lists all overrides. herd unisolate reverts.
Bootstrap a bare worktree
A worktree made with plain git worktree add (the PR, issue, and CI recipes in other skills, at .claude/worktrees/<name>) has no vendor/, node_modules/, or .env. Make it runnable from inside the worktree, with main set to the main checkout (git worktree list --porcelain | sed -n '1s/^worktree //p'):
- Dependencies.
cp -Rc "$main/vendor" vendor(an APFS clone: instant, no extra disk), thencomposer installso it matches this branch's lock. Do the same fornode_moduleswhen the run builds assets. Each tree owns a real copy: Composer's autoloader resolvesapp/andtests/relative tovendor/, so a symlinkedvendor/makes Pest run the main checkout's code. - Environment. Copy
.env(and.env.testingwhen present) from$main. When the calling skill gives the run its own database, setDB_DATABASEto that name in both. - Proof.
git rev-parse HEADequals the commit the run means to test, andtest ! -L vendorpasses. Run nothing until both hold.
Per-Worktree Isolation Rules
| Concern | Rule |
vendor/ | Always per-worktree. Never symlink. |
node_modules/ | Always per-worktree. Never symlink. Use pnpm for fastest installs (content-addressable store). |
.env | Copy from main, rewrite APP_URL, DB_DATABASE, CACHE_PREFIX, SESSION_COOKIE, REDIS_PREFIX. |
APP_KEY | Run php artisan key:generate in each worktree. |
| Database | SQLite: per-worktree file. MySQL/Postgres: per-worktree DB name <app>_<suffix>. |
| Redis | Set unique REDIS_PREFIX (or different REDIS_DB index). |
storage/, bootstrap/cache/ | Per-worktree. Run php artisan optimize:clear after install. |
storage/app/public symlink | Re-run php artisan storage:link in the new worktree. |
Full rationale: references/isolation.md. DB strategy details (sharing seeds, schema dumps, fresh vs. migrate): references/db-strategies.md.
Common Pitfalls
- Sharing
vendor/via symlink: breaks when branches have different package versions; autoload class maps drift. - Forgetting
php artisan key:generate: encrypted cookies/sessions fail silently across worktrees that shareAPP_KEY. - Same
SESSION_COOKIEacross*.testsiblings: cookies leak between branches because they share the.testparent domain. Set a uniqueSESSION_COOKIEper worktree. - Same Redis DB without prefix: cache keys collide; one branch invalidates another's cache.
- Running
composer installagainst a stalecomposer.lockafter rebasing: always re-run install after switching base branches inside a worktree. - Herd not picking up new worktree: happens if the parent isn't parked or if the worktree directory name contains characters Herd rejects (stick to
[a-z0-9-]).
Quick Diagnostics
herd parked # confirm parent is parked
herd isolated # list per-site PHP overrides
herd which-php # PHP version Herd resolves for current dir
git worktree list # all worktrees + branches
ls -1 ../ | grep <app> # worktree dirs as Herd sees themIf a .test URL 404s: check herd parked includes the parent, dir name is lowercase, and php artisan route:list works inside the worktree.
Out of Scope
- Valet: different tool. Herd-only here.
- Linux Herd: paths and CLI differ; this skill assumes macOS Herd.
- Docker / Sail: covered by other workflows. Worktrees still work but routing is via Docker, not Herd.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

