Git worktrees + isolated Convex deployments = Safe parallel feature development
A comprehensive workflow system for managing git worktrees with isolated Convex database deployments. Perfect for teams working on multiple features simultaneously without database conflicts.
This skill provides automation scripts and detailed documentation for creating isolated development environments using:
- Git Worktrees - Multiple working directories from the same repository
- Convex Deployments - Separate cloud databases per feature branch
- Port Management - Auto-assigned ports with gap-filling
- Data Snapshots - Clone data from main to test with realistic datasets
When working on features that involve database schema changes:
❌ Without This System:
- Schema changes in one branch break other branches
- Can't test multiple features simultaneously
- Risk of data corruption from conflicting schemas
- Constantly switching branches and losing context
✅ With This System:
- Each feature has isolated database (safe experimentation)
- Run multiple dev servers concurrently (different ports)
- Test schema changes without affecting main development
- Clean separation between features
- Windows PowerShell (PowerShell 5.1+)
- PowerShell Core (cross-platform, but see caveats below)
Get-NetTCPConnection(Windows only)Stop-Processwith network connection (Windows only)
For Unix/Mac Users:
- Scripts work but port conflict detection won't function
- Manual port management required
- Consider creating bash equivalents (contributions welcome!)
Before using this skill, ensure you have:
-
Git 2.15+ (for worktree support)
git --version
-
Node.js & npm (for Convex CLI and Next.js)
node --version npm --version
-
Convex CLI (install globally)
npm install -g convex
-
Convex Account (authenticated)
npx convex dev # Authenticate if needed
- Next.js project (or similar framework using
npm run dev) - Convex backend (
convex/directory with functions) .env.localfile in main repo (will be copied to worktrees)
cd ~/projects
git clone https://github.com/yourusername/convex-worktree-skill.git# Copy scripts
cp convex-worktree-skill/scripts/* your-project/scripts/
# Copy skill documentation (optional, for Claude Code integration)
cp -r convex-worktree-skill/skills your-project/.claude/skills/worktree-development/Critical: Update project-specific variables
Edit these files and replace {project-name} placeholders:
# Line 18: Change this
$WorktreeDir = "..\{project-name}-$FeatureName"
# To:
$WorktreeDir = "..\myapp-$FeatureName"
# Line 137: Change this
$ConvexProjectName = "{project-name}-$FeatureName"
# To:
$ConvexProjectName = "myapp-$FeatureName"
# Line 60 & 62: Change main port if needed (default 4030)
$PortTracking = @{
main = 4030 # Your main repo's port
}# Line 20: Change this
$WorktreeDir = "..\{project-name}-$FeatureName"
# To:
$WorktreeDir = "..\myapp-$FeatureName"# Line 74: Change this
$PortKey = if ($IsMain) { "main" } else { $WorktreeName -replace '^{project-name}-', '' }
# To:
$PortKey = if ($IsMain) { "main" } else { $WorktreeName -replace '^myapp-', '' }# From your main project directory
.\scripts\list-worktrees.ps1
# Should show your main repo# From main project directory
.\scripts\create-feature-worktree.ps1 user-auth
# What happens:
# ✅ Git worktree created: ../myapp-user-auth
# ✅ Port assigned: 4031
# ✅ Convex project created: myapp-user-auth
# ✅ Data cloned from main deployment
# ✅ Dependencies installed# Navigate to worktree
cd ..\myapp-user-auth
# Terminal 1: Start Convex dev server
npx convex dev
# Terminal 2: Start Next.js dev server
npm run dev # Runs on assigned port (e.g., 4031)
# Access: http://localhost:4031# Inside worktree directory
..\myapp\scripts\sync-worktree-data.ps1
# Or sync specific tables
..\myapp\scripts\sync-worktree-data.ps1 -Tables "users,profiles"See docs/merge-workflow.md for complete merge process.
# Push to remote (backup)
git push -u origin user-auth
# Commit changes (excluding port changes)
git add -A
git reset -- package.json # Don't commit port change
git commit -m "feat: add user authentication"
git push
# Switch to main and merge
cd ..\myapp
git checkout main
git merge user-auth --no-ff
git push origin main# From main repo
.\scripts\delete-feature-worktree.ps1 user-auth
# What gets deleted:
# ✅ Local worktree folder (~500MB freed)
# ✅ Port reservation freed
# ⚠️ Remote branch preserved (recommended!)
# ⚠️ Convex deployment (manual cleanup required)Comprehensive guides in the skills/ directory:
- SKILL.md - Overview, quick reference, critical warnings
- setup-teardown.md - Creating and deleting worktrees
- environment-variables.md - Port management, .env.local handling
- data-management.md - Data snapshots, syncing, migration
- schema-migrations.md - Handling schema changes safely
- merge-workflow.md - Merging worktrees with port conflict prevention
- troubleshooting.md - Common issues and solutions
- New to worktrees? Start with SKILL.md
- Port conflicts? See troubleshooting.md
- Data out of date? See data-management.md
- Schema changes? See schema-migrations.md
- One command creates complete isolated environment
- Auto-assigns unique ports (gap-filling algorithm)
- Clones Convex data from main deployment
- Copies environment variables
- Installs dependencies
- Each worktree has separate Convex project
- Independent schemas (test breaking changes safely)
- Isolated data (no conflicts with main)
- Point-in-time snapshots from main
- Auto-assigned ports starting at 4031
- Gap-filling reuses freed ports
- Tracked in
.worktree-ports.json - No manual port configuration needed
- Re-sync data when worktree becomes stale
- Selective table sync support
- Automatic backup before sync
- Verification after import
- Delete local worktree, keep remote branch
- Preserve git history automatically
- Free disk space efficiently
- Reminder for Convex cleanup
-
Large features requiring schema changes
- Test database modifications safely
- No risk to main development database
-
Experimental features
- Try ideas without committing to main
- Easy to discard if doesn't work
-
Parallel development
- Work on multiple features simultaneously
- Each with independent database state
-
Features needing production-like data
- Clone complete dataset from main
- Test with realistic scenarios
- Quick bug fixes - Too much setup overhead
- Purely frontend changes - No database interaction needed
- Changes needing real-time main data - Worktree data is snapshot
- Hotfixes - Time-critical, no time for worktree setup
your-project/ # Main repo (port 4030)
├── .git/ # Git data directory
├── convex/ # Convex functions
├── src/ # Next.js source
├── .env.local # Environment variables
├── package.json # Port: 4030
└── scripts/
├── create-feature-worktree.ps1
├── delete-feature-worktree.ps1
├── sync-worktree-data.ps1
└── list-worktrees.ps1
../your-project-feature-1/ # Worktree 1 (port 4031)
├── .git # File (pointer to main)
├── convex/ # Same functions
├── src/ # Same source
├── .env.local # Different Convex URL
└── package.json # Port: 4031
../your-project-feature-2/ # Worktree 2 (port 4032)
├── .git # File (pointer to main)
└── ... # Isolated environment
Main Repo Worktree 1 Worktree 2
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Main Project │ │ feature-1 │ │ feature-2 │
│ │ │ │ │ │
│ Port: 4030 │ │ Port: 4031 │ │ Port: 4032 │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Main DB │ │ Feature-1 DB │ │ Feature-2 DB │
│ (dev) │─snapshot─▶│ (isolated) │ │ (isolated) │
│ │ │ │ │ │
│ Schema v1 │ │ Schema v2 │ │ Schema v3 │
└──────────────┘ └──────────────┘ └──────────────┘
# 1. Create isolated worktree
.\scripts\create-feature-worktree.ps1 schema-update
# 2. Modify schema in worktree
cd ..\myapp-schema-update
# Edit convex/schema.ts
# 3. Test migration
npx convex dev # Schema auto-updates
# Test with existing data
# 4. If successful, merge to main
# If failed, delete worktree (no harm to main)# Developer A
.\scripts\create-feature-worktree.ps1 user-profiles
cd ..\myapp-user-profiles
npx convex dev # Port 4031
npm run dev
# Developer B (different feature, same machine)
.\scripts\create-feature-worktree.ps1 payment-flow
cd ..\myapp-payment-flow
npx convex dev # Port 4032
npm run dev
# Both work independently, no conflicts!# After 7 days, main DB has new data
cd ..\myapp-feature
..\myapp\scripts\sync-worktree-data.ps1
# Fresh data from main, continue working# Check which worktree is using it
..\myapp\scripts\list-worktrees.ps1
# Kill process on port
Stop-Process -Id (Get-NetTCPConnection -LocalPort 4031).OwningProcess -Force# Check which deployment you're connected to
Get-Content .env.local | Select-String "CONVEX"
# Verify convex dev is running in correct directory
# Must run in worktree directory, not main# Re-sync from main
..\myapp\scripts\sync-worktree-data.ps1# Option 1: Sync data (gets main's schema)
..\myapp\scripts\sync-worktree-data.ps1
# Option 2: Pull schema changes
git merge mainSee troubleshooting.md for complete diagnostic commands.
# As soon as worktree is created
git push -u origin feature-nameWhy: Backup, recovery, team visibility
# If worktree is > 7 days old
..\myapp\scripts\sync-worktree-data.ps1Why: Keep data fresh, avoid stale state
# Export before deleting worktree
npx convex export --table important_table --path data.json
# After merge, import to main
npx convex import --table important_table --path data.jsonWhy: Don't lose configurations, templates, test data
# Check for old worktrees
..\myapp\scripts\list-worktrees.ps1
# Delete merged worktrees
.\scripts\delete-feature-worktree.ps1 old-featureWhy: Free disk space (~500MB per worktree), keep workspace clean
- Port management uses Windows-specific cmdlets
- Unix/Mac users need bash equivalents (contributions welcome!)
- Worktree data doesn't auto-update from main
- Must manually re-sync if main DB changes significantly
- Not suitable for features needing real-time main data
- Scripts don't auto-delete Convex deployments
- Must manually delete from dashboard
- Dev deployments are free (no cost to leave them)
- Each worktree ~500MB (full repo copy)
- Multiple worktrees can consume significant disk space
- Regular cleanup recommended
Contributions welcome! Priority areas:
- Bash equivalents for Unix/Mac support
- Port detection for Unix (using
lsofinstead ofGet-NetTCPConnection) - Cross-platform PowerShell compatibility
- Auto-delete Convex deployments (requires Convex API)
- Selective data sync (table filtering)
- Automated merge workflows
- GUI for worktree management
- VS Code extension
- Analytics (worktree usage stats)
# Copy to your project's Claude Code skills directory
cp -r convex-worktree-skill/skills your-project/.claude/skills/worktree-development/See CONTRIBUTING.md for development guidelines (if exists).
MIT License - see LICENSE for details.
- Convex for serverless database platform
- Git for worktree functionality
- Original concept developed for Zwoofi project
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: See
docs/directory
- Initial release
- Windows PowerShell scripts
- Complete documentation suite
- Port management with gap-filling
- Data sync and migration tools
- Automated worktree creation/deletion
Made with ❤️ by developers who got tired of schema conflicts