Skip to content

About

Git worktrees + isolated Convex deployments for safe parallel feature development

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convex Worktree Development Skill

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.


What Is This?

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

The Problem It Solves

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

Platform Compatibility

Currently Supported

  • Windows PowerShell (PowerShell 5.1+)
  • PowerShell Core (cross-platform, but see caveats below)

Known Limitations

⚠️ Port Management uses Windows-specific cmdlets:

  • Get-NetTCPConnection (Windows only)
  • Stop-Process with 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!)

Prerequisites

Before using this skill, ensure you have:

Required

  • 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

Project Requirements

  • Next.js project (or similar framework using npm run dev)
  • Convex backend (convex/ directory with functions)
  • .env.local file in main repo (will be copied to worktrees)

Installation

1. Clone This Repository

cd ~/projects
git clone https://github.com/yourusername/convex-worktree-skill.git

2. Copy Files to Your Project

# 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/

3. Customize Scripts

Critical: Update project-specific variables

Edit these files and replace {project-name} placeholders:

scripts/create-feature-worktree.ps1

# 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
}

scripts/delete-feature-worktree.ps1

# Line 20: Change this
$WorktreeDir = "..\{project-name}-$FeatureName"
# To:
$WorktreeDir = "..\myapp-$FeatureName"

scripts/list-worktrees.ps1

# Line 74: Change this
$PortKey = if ($IsMain) { "main" } else { $WorktreeName -replace '^{project-name}-', '' }
# To:
$PortKey = if ($IsMain) { "main" } else { $WorktreeName -replace '^myapp-', '' }

4. Verify Setup

# From your main project directory
.\scripts\list-worktrees.ps1
# Should show your main repo

Quick Start

Create a Worktree

# 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

Work in Worktree

# 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

Sync Data (If Stale)

# Inside worktree directory
..\myapp\scripts\sync-worktree-data.ps1

# Or sync specific tables
..\myapp\scripts\sync-worktree-data.ps1 -Tables "users,profiles"

Merge to Main

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

Delete Worktree

# 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)

Documentation

Comprehensive guides in the skills/ directory:

Core Documentation

Quick Links


Features

✨ Automated Worktree Creation

  • One command creates complete isolated environment
  • Auto-assigns unique ports (gap-filling algorithm)
  • Clones Convex data from main deployment
  • Copies environment variables
  • Installs dependencies

🔒 Database Isolation

  • Each worktree has separate Convex project
  • Independent schemas (test breaking changes safely)
  • Isolated data (no conflicts with main)
  • Point-in-time snapshots from main

🚀 Port Management

  • Auto-assigned ports starting at 4031
  • Gap-filling reuses freed ports
  • Tracked in .worktree-ports.json
  • No manual port configuration needed

🔄 Data Synchronization

  • Re-sync data when worktree becomes stale
  • Selective table sync support
  • Automatic backup before sync
  • Verification after import

🧹 Clean Workflows

  • Delete local worktree, keep remote branch
  • Preserve git history automatically
  • Free disk space efficiently
  • Reminder for Convex cleanup

When to Use Worktrees

✅ Perfect For

  • 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

❌ Not Ideal For

  • 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

Architecture

Directory Structure

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

Convex Deployments

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    │
└──────────────┘          └──────────────┘           └──────────────┘

Common Workflows

Scenario 1: Testing Schema Change

# 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)

Scenario 2: Multiple Features in Parallel

# 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!

Scenario 3: Data Becomes Stale

# After 7 days, main DB has new data
cd ..\myapp-feature
..\myapp\scripts\sync-worktree-data.ps1

# Fresh data from main, continue working

Troubleshooting

Port Already in Use

# Check which worktree is using it
..\myapp\scripts\list-worktrees.ps1

# Kill process on port
Stop-Process -Id (Get-NetTCPConnection -LocalPort 4031).OwningProcess -Force

Convex Deployment Issues

# 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

Data Seems Stale

# Re-sync from main
..\myapp\scripts\sync-worktree-data.ps1

Schema Mismatch Errors

# Option 1: Sync data (gets main's schema)
..\myapp\scripts\sync-worktree-data.ps1

# Option 2: Pull schema changes
git merge main

See troubleshooting.md for complete diagnostic commands.


Best Practices

1. Push to Remote Early

# As soon as worktree is created
git push -u origin feature-name

Why: Backup, recovery, team visibility

2. Sync Data Regularly

# If worktree is > 7 days old
..\myapp\scripts\sync-worktree-data.ps1

Why: Keep data fresh, avoid stale state

3. Migrate Important Data Before Deletion

# 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.json

Why: Don't lose configurations, templates, test data

4. Clean Up Regularly

# Check for old worktrees
..\myapp\scripts\list-worktrees.ps1

# Delete merged worktrees
.\scripts\delete-feature-worktree.ps1 old-feature

Why: Free disk space (~500MB per worktree), keep workspace clean


Limitations

1. Windows PowerShell Only (Currently)

  • Port management uses Windows-specific cmdlets
  • Unix/Mac users need bash equivalents (contributions welcome!)

2. Data Is Point-in-Time Snapshot

  • 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

3. Manual Convex Cleanup Required

  • Scripts don't auto-delete Convex deployments
  • Must manually delete from dashboard
  • Dev deployments are free (no cost to leave them)

4. Disk Space Overhead

  • Each worktree ~500MB (full repo copy)
  • Multiple worktrees can consume significant disk space
  • Regular cleanup recommended

Contributing

Contributions welcome! Priority areas:

High Priority

  • Bash equivalents for Unix/Mac support
  • Port detection for Unix (using lsof instead of Get-NetTCPConnection)
  • Cross-platform PowerShell compatibility

Medium Priority

  • Auto-delete Convex deployments (requires Convex API)
  • Selective data sync (table filtering)
  • Automated merge workflows

Low Priority

  • GUI for worktree management
  • VS Code extension
  • Analytics (worktree usage stats)

Installation for Users

# 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).


License

MIT License - see LICENSE for details.


Acknowledgments

  • Convex for serverless database platform
  • Git for worktree functionality
  • Original concept developed for Zwoofi project

Support


Changelog

v1.0.0 (2025-01-XX)

  • 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

About

Git worktrees + isolated Convex deployments for safe parallel feature development

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages