Token导航 LogoToken导航TokenDH.com
研究检索权限需确认github未标认证来源可访问许可证需确认审计未展示

@gw-multi-worktree-devGW 多工作树开发

Agent Skill

@gw-multi-worktree-dev 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

490

周安装

20

GitHub Stars

公开资料未说明

下载量

158
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:@gw-multi-worktree-dev(GW 多工作树开发)
来源仓库:https://github.com/mthines/gw-tools
仓库路径:skills/@gw-multi-worktree-dev
安装命令:
npx skills add mthines/gw-tools --skill "@gw-multi-worktree-dev"
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

AgentSkills.tonpx skills
npx skills add mthines/gw-tools --skill "@gw-multi-worktree-dev"

简介

@gw-multi-worktree-dev 支持多工作树并行开发环境管理。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中同时处理多个 feature 分支。
  • 自动同步主分支变动,减少合并冲突风险。
  • 安装命令:npx skills add mthines/gw-tools --skill "@gw-multi-worktree-dev"。
  • 使用前应熟悉 Git worktree 基础命令以避免误操作。

SKILL.md

Multi-Worktree Development - Comprehensive Guide

Advanced patterns for developing across multiple Git worktrees simultaneously.

Table of Contents

  1. Parallel Development Workflows
  2. Dependency Management
  3. File Synchronization
  4. Database and Service Management
  5. Testing Workflows
  6. Build Artifact Management
  7. Team Collaboration
  8. Performance and Optimization

1. Parallel Development Workflows

Benefits of Parallel Development

Working on multiple branches simultaneously eliminates:

  • Context switching overhead
  • IDE reindexing delays
  • Stashing/committing incomplete work
  • Mental context loss

Setting Up Multiple Worktrees

# Create worktrees for different features
gw add feat/user-auth
gw add feat/payment-gateway
gw add feat/email-notifications

# List all worktrees
gw list

Managing Mental Context

Strategy 1: Dedicated terminals

# Terminal 1: User Auth
gw cd feat/user-auth
npm run dev

# Terminal 2: Payment Gateway
gw cd feat/payment-gateway
npm run dev

Strategy 2: Terminal multiplexer (tmux)

# Create named sessions
tmux new -s auth
gw cd feat/user-auth

tmux new -s payments
gw cd feat/payment-gateway

# Switch between sessions
tmux attach -t auth
tmux attach -t payments

Strategy 3: IDE workspaces

VS Code multi-root workspace:

{
  "folders": [
    {"name": "Auth Feature", "path": "../feat/user-auth"},
    {"name": "Payments", "path": "../feat/payment-gateway"}
  ]
}

Quick Context Switching

# Fast navigation with partial matching
gw cd auth     # Matches feat/user-auth
gw cd pay      # Matches feat/payment-gateway

2. Dependency Management

Understanding the Problem

Each worktree has independent working files, including node_modules:

repo.git/
├── main/
│   └── node_modules/     # ~500MB
├── feat/user-auth/
│   └── node_modules/     # ~500MB (duplicate!)
└── feat/payment-gateway/
    └── node_modules/     # ~500MB (duplicate!)

With 5 worktrees: 2.5GB of duplicated dependencies!

Strategy 1: Accept Duplication (Simplest)

Pros: Full isolation, no conflicts Cons: Disk space usage

# Each worktree installs independently
gw add feat/new-feature
gw cd feat/new-feature
npm install

Best for: Testing different dependency versions, small projects.

Strategy 2: Use pnpm (Recommended)

pnpm uses a content-addressable store that deduplicates packages:

# Install pnpm
npm install -g pnpm

# In each worktree
gw cd feat/user-auth
pnpm install  # Uses shared store

gw cd feat/payment-gateway
pnpm install  # Reuses cached packages

Result: Near-zero duplication, full isolation.

Strategy 3: Symlink node_modules (Advanced)

Warning: Only works if all worktrees need identical dependencies.

# In feature worktree
gw cd feat/user-auth
rm -rf node_modules
ln -s ../main/node_modules node_modules

Risks:

  • Package version conflicts
  • Native modules may break
  • Hoisting issues

Best for: Read-only testing, identical environments.

Strategy 4: Post-Add Hook for Auto-Install

gw init --post-add "npm install"

Now every gw add automatically installs dependencies.


3. File Synchronization

Using gw sync

Sync files between worktrees without recreating them:

# Sync all autoCopyFiles from config
gw sync feat/user-auth

# Sync specific file from main to feature branch
gw sync feat/user-auth .env

# Sync from specific source
gw sync --from staging feat/user-auth .env

# Sync multiple files
gw sync feat/user-auth .env secrets/ config/local.json

Common Sync Patterns

Pattern 1: Update secrets across all worktrees

# After updating .env in main - sync autoCopyFiles to all worktrees
for worktree in $(gw list | grep -v main | awk '{print $1}' | xargs -n1 basename); do
  gw sync "$worktree"
done

# Or sync specific file
for worktree in $(gw list | grep -v main | awk '{print $1}' | xargs -n1 basename); do
  gw sync "$worktree" .env
done

Pattern 2: Propagate config changes

# Updated shared config in main
gw cd feat/user-auth
gw sync --from main feat/user-auth config/shared.json

Pattern 3: Hot-swap environment

# Test feature with production-like config
gw sync --from production-mirror feat/user-auth .env

Dry Run Mode

Preview what would be synced:

gw sync --dry-run feat/user-auth .env secrets/

4. Database and Service Management

Database Isolation Strategies

Strategy 1: Separate databases per worktree

# In feat/user-auth/.env
DATABASE_URL=postgresql://localhost:5432/myapp_auth

# In feat/payment-gateway/.env
DATABASE_URL=postgresql://localhost:5432/myapp_payments

Strategy 2: Docker Compose per worktree

Create docker-compose.worktree.yml:

version: '3.8'
services:
  db:
    image: postgres:15
    ports:
      - "${DB_PORT:-5432}:5432"
    environment:
      POSTGRES_DB: myapp_${WORKTREE_NAME:-dev}
# In each worktree
export WORKTREE_NAME=$(basename $PWD)
export DB_PORT=5433  # Different port per worktree
docker-compose -f docker-compose.worktree.yml up -d

Strategy 3: Shared database with schema prefixes

-- feat/user-auth uses schema: auth_feature
CREATE SCHEMA auth_feature;

-- feat/payment-gateway uses schema: payments_feature
CREATE SCHEMA payments_feature;

Port Management

Avoid port conflicts between worktrees:

# main/.env
PORT=3000
DB_PORT=5432

# feat/user-auth/.env
PORT=3001
DB_PORT=5433

# feat/payment-gateway/.env
PORT=3002
DB_PORT=5434

Service Orchestration

Running frontend and backend in separate worktrees:

# Terminal 1: API (main branch)
gw cd main
npm run dev:api  # Port 3001

# Terminal 2: Frontend (feature branch)
gw cd feat/new-ui
API_URL=http://localhost:3001 npm run dev:web  # Port 3000

5. Testing Workflows

Parallel Testing Across Environments

Test the same feature in multiple environments:

# Create test worktrees
gw add test-node18 --force
gw add test-node20 --force

# Terminal 1: Node 18
gw cd test-node18
nvm use 18
npm install && npm test

# Terminal 2: Node 20
gw cd test-node20
nvm use 20
npm install && npm test

CI/CD Integration

GitHub Actions with worktrees:

jobs:
  test:
    strategy:
      matrix:
        node: [18, 20, 22]
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node ${{ matrix.node }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
      - run: npm install
      - run: npm test

Local simulation:

#!/bin/bash
# test-matrix.sh
for version in 18 20 22; do
  gw add "test-node$version" --force
  (
    gw cd "test-node$version"
    nvm use "$version"
    npm install
    npm test
  ) &
done
wait
echo "All tests complete"

Test Isolation

Each worktree can have different test configurations:

# In feat/user-auth
npm test -- --testPathPattern="auth"

# In feat/payment-gateway
npm test -- --testPathPattern="payment"

6. Build Artifact Management

Separate Build Outputs

Each worktree maintains independent build artifacts:

repo.git/
├── main/
│   └── dist/        # Production build
├── feat/user-auth/
│   └── dist/        # Feature build
└── feat/payment-gateway/
    └── dist/        # Different feature build

Sharing Build Caches

Turborepo/Nx caching:

# Turbo's cache is shared automatically
gw cd feat/user-auth
pnpm turbo build  # Fast: uses cache from main

Manual cache sharing:

# Share .next/cache between worktrees
ln -s ../main/.next/cache .next/cache

Clean Build Strategies

When you need guaranteed clean builds:

# Remove build artifacts
rm -rf dist/ .next/ build/

# Fresh install and build
rm -rf node_modules/
npm install
npm run build

7. Team Collaboration

Code Review Workflows

Reviewer worktree pattern:

# Create worktree from PR branch
gw add review-pr-123
gw cd review-pr-123

# Review code, run tests
npm install
npm test
npm run dev  # Manual testing

# Leave review comments
# ...

# Clean up
gw remove review-pr-123

Pair Programming

Each developer in their own worktree:

# Developer A
gw add pair/feature-x-alice
gw cd pair/feature-x-alice
# Work on frontend...

# Developer B
gw add pair/feature-x-bob
gw cd pair/feature-x-bob
# Work on backend...

# Sync changes via git
git pull origin pair/feature-x

Demo Environments

One worktree per demo:

# Create demo worktrees
gw add demo/client-a
gw add demo/client-b

# Each with different configuration
# demo/client-a/.env
FEATURE_FLAGS=clientA

# demo/client-b/.env
FEATURE_FLAGS=clientB

8. Performance and Optimization

Monitoring Disk Usage

# Check worktree sizes
du -sh /path/to/repo.git/*/

# Find large node_modules
du -sh /path/to/repo.git/*/node_modules/ | sort -h

Cleanup Strategies

Quick cleanup:

If you need to quickly remove all temporary worktrees:

# Preview what would be removed
gw prune --clean --dry-run

# Remove all worktrees that are clean (no uncommitted/unpushed changes)
gw prune --clean

This is useful when:

  • Switching between projects
  • Low on disk space
  • Want to start fresh with minimal worktrees
  • Before archiving a project

Age-based cleanup (regular maintenance):

# Remove all safe worktrees (default)
gw clean --dry-run  # Preview
gw clean            # Remove

# Or remove only worktrees older than configured threshold (default: 7 days)
gw clean --use-autoclean-threshold --dry-run  # Preview old worktrees
gw clean --use-autoclean-threshold            # Remove old worktrees

Prune stale references:

# Clean up administrative data for deleted worktrees
gw prune

Resource Balancing

Limit concurrent worktrees:

  • Development machine: 3-5 active worktrees
  • CI machine: As many as needed (ephemeral)

Memory considerations:

  • Each running dev server uses memory
  • Each node_modules uses disk space
  • Database containers use memory + disk

Recommended setup:

# Keep essential worktrees
main/           # Always ready
feat/current/   # Active feature
review/         # Code review (temporary)
hotfix/         # Emergency fixes (temporary)

When NOT to Use Multiple Worktrees

Consider alternatives when:

  • Single small fix → Just commit and switch back
  • Same file being edited → Use branches instead
  • Limited disk space → Use branch switching
  • Team uses different workflow → Align first

Summary

You now understand:

  • ✅ Managing parallel development workflows effectively
  • ✅ Dependency strategies (pnpm recommended)
  • ✅ Keeping files in sync with gw sync
  • ✅ Database and service isolation patterns
  • ✅ Parallel testing across environments
  • ✅ Build artifact management
  • ✅ Team collaboration patterns
  • ✅ Performance optimization techniques

Next Steps

  1. Set up pnpm for efficient dependency management
  2. Configure post-add hooks for automatic setup
  3. Create team guidelines for worktree usage
  4. Implement cleanup automation

Additional Resources


*Part of the gw-tools skills collection*

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.52%
按下载量换算58

Claude

31.02%
按下载量换算49

Cursor

18.99%
按下载量换算30

Gemini CLI

9.77%
按下载量换算15

安全审计

暂无安全审计结果可展示。

权限和风险

权限需确认

当前来源未能明确判断权限范围,默认进入异常复核队列。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills