Work on multiple branches simultaneously without switching branches or duplicating dependencies.
# Create a worktree for an existing branch
/git-tree feature-branch
# Work in the new worktree
cd local-frontend/gittree-feature-branch
# Dependencies are already available via symlinks
git status
./vendor/bin/sail artisan testGit worktrees let you checkout multiple branches at once into separate directories. The Lindris implementation adds:
- Automatic symlinks to
vendor/,node_modules/, and.env - Shared Docker containers (no duplicate environments)
- Works seamlessly with existing tools and workflows
# Create and automatically cd to worktree (default)
/git-tree feature-branch
# Create without changing directory
/git-tree feature-branch --no-cdThe command will:
- Prompt to create the branch if it doesn't exist
- Create the worktree in a parallel directory
- Set up symlinks to dependencies automatically
- Automatically cd to the new worktree (unless
--no-cdis specified)
# Create and automatically cd to worktree (default)
./bin/git-tree.sh feature-branch
# Create without changing directory
./bin/git-tree.sh feature-branch --no-cdlindris-monorepo/
├── local-frontend/
│ ├── lindris-frontend/ # Main repository
│ │ ├── vendor/ # Real dependencies
│ │ ├── node_modules/ # Real dependencies
│ │ └── .env # Real environment
│ └── gittree-feature-branch/ # New worktree
│ ├── vendor -> ../lindris-frontend/vendor/
│ ├── node_modules -> ../lindris-frontend/node_modules/
│ ├── .env -> ../lindris-frontend/.env
│ └── [all your code from feature-branch]
# After creating a worktree, you're automatically in the new directory
# (unless you used --no-cd flag)
# All standard git commands work
git status
git commit -m "Changes"
git push
# Dependencies are already available
./vendor/bin/sail artisan test
./vendor/bin/sail npm run dev
npm run build
# Docker containers are shared with main repo
./vendor/bin/sail up # Uses existing containersgit worktree list# Option 1: Use git command
git worktree remove gittree-feature-branch
# Option 2: Delete directory and prune
rm -rf local-frontend/gittree-feature-branch
git worktree prune# Main repo: feature A
cd local-frontend/lindris-frontend
git checkout feature-a
# Worktree 1: bugfix (automatically cd's there)
/git-tree bugfix-123
# Now in: local-frontend/gittree-bugfix-123
# Worktree 2: reviewing PR (automatically cd's there)
/git-tree pr-review-456
# Now in: local-frontend/gittree-pr-review-456/git-tree pr-123-feature
# You're now in the worktree directory - ready to test immediately
./vendor/bin/sail artisan testAll worktrees share the same vendor/, node_modules/, and .env:
- Pro: No reinstalling dependencies, saves disk space
- Con: If branches need different dependency versions, use a full clone instead
Worktrees use the main repo's Docker containers:
- Pro: No duplicate containers, consistent database state
- Con: Database changes affect all worktrees
All worktrees share the same git repository:
- Cannot checkout the same branch in multiple worktrees
- Commits in any worktree affect the shared repository
- Use unique branches for each worktree
Issue: The pre-commit hook in the frontend repository currently has issues when running from worktrees due to Sail container context.
Status: Needs investigation and fix
Details:
- Pre-commit hooks attempt to run tests via Sail
- Worktrees may not have proper Docker environment context
- Similar to pre-push hook, needs Docker environment detection logic
Potential Solution:
- Add
isDockerEnvironment()function to pre-commit hook (similar to pre-push) - Detect if running inside Docker vs. from worktree
- Adjust Sail command execution based on context
Workaround:
- Temporarily disable pre-commit hook when working in worktrees
- Run tests manually before committing
- Or commit from main repo instead of worktree
Feature Request: Enable swapping which worktree is served by LocalWP/webserver for UI testing.
Status: Future enhancement
Use Case:
- Test UI changes from worktree in browser
- Compare UI behavior between branches
- Quickly switch which branch is served without restarting containers
Potential Solutions:
- Symlink Swapping:
- Make the main repo directory a symlink to current active worktree
- Script to swap symlink target:
./bin/git-tree-swap.sh feature-branch - LocalWP/Docker follows the symlink to serve correct branch
Considerations:
- How to handle shared dependencies (vendor/node_modules remain symlinked)
- Database state (shared across all worktrees)
- Asset building (each worktree needs compiled assets)
- Container restart time vs. symlink switching speed
If symlinks aren't working:
ls -la vendor node_modules .env # Check symlinks existIf needed, recreate manually:
ln -s ../lindris-frontend/vendor vendor
ln -s ../lindris-frontend/node_modules node_modules
ln -s ../lindris-frontend/.env .envFor branches with different dependencies:
# Remove symlinks and install separately
rm vendor node_modules
composer install
npm installEnsure main repo's containers are running:
cd local-frontend/lindris-frontend
./vendor/bin/sail up -d