git-worktree-manager

16
0
Source

Git Worktree Manager

Install

mkdir -p .claude/skills/git-worktree-manager && curl -L -o skill.zip "https://mcp.directory/api/skills/download/2081" && unzip -o skill.zip -d .claude/skills/git-worktree-manager && rm skill.zip

Installs to .claude/skills/git-worktree-manager

About this skill

Git Worktree Manager

Tier: POWERFUL
Category: Engineering
Domain: Parallel Development & Branch Isolation

Overview

Use this skill to run parallel feature work safely with Git worktrees. It standardizes branch isolation, port allocation, environment sync, and cleanup so each worktree behaves like an independent local app without stepping on another branch.

This skill is optimized for multi-agent workflows where each agent or terminal session owns one worktree.

Core Capabilities

  • Create worktrees from new or existing branches with deterministic naming
  • Auto-allocate non-conflicting ports per worktree and persist assignments
  • Copy local environment files (.env*) from main repo to new worktree
  • Optionally install dependencies based on lockfile detection
  • Detect stale worktrees and uncommitted changes before cleanup
  • Identify merged branches and safely remove outdated worktrees

When to Use

  • You need 2+ concurrent branches open locally
  • You want isolated dev servers for feature, hotfix, and PR validation
  • You are working with multiple agents that must not share a branch
  • Your current branch is blocked but you need to ship a quick fix now
  • You want repeatable cleanup instead of ad-hoc rm -rf operations

Key Workflows

1. Create a Fully-Prepared Worktree

  1. Pick a branch name and worktree name.
  2. Run the manager script (creates branch if missing).
  3. Review generated port map.
  4. Start app using allocated ports.
python scripts/worktree_manager.py \
  --repo . \
  --branch feature/new-auth \
  --name wt-auth \
  --base-branch main \
  --install-deps \
  --format text

If you use JSON automation input:

cat config.json | python scripts/worktree_manager.py --format json
# or
python scripts/worktree_manager.py --input config.json --format json

2. Run Parallel Sessions

Recommended convention:

  • Main repo: integration branch (main/develop) on default port
  • Worktree A: feature branch + offset ports
  • Worktree B: hotfix branch + next offset

Each worktree contains .worktree-ports.json with assigned ports.

3. Cleanup with Safety Checks

  1. Scan all worktrees and stale age.
  2. Inspect dirty trees and branch merge status.
  3. Remove only merged + clean worktrees, or force explicitly.
python scripts/worktree_cleanup.py --repo . --stale-days 14 --format text
python scripts/worktree_cleanup.py --repo . --remove-merged --format text

4. Docker Compose Pattern

Use per-worktree override files mapped from allocated ports. The script outputs a deterministic port map; apply it to docker-compose.worktree.yml.

See docker-compose-patterns.md for concrete templates.

5. Port Allocation Strategy

Default strategy is base + (index * stride) with collision checks:

  • App: 3000
  • Postgres: 5432
  • Redis: 6379
  • Stride: 10

See port-allocation-strategy.md for the full strategy and edge cases.

Script Interfaces

  • python scripts/worktree_manager.py --help
    • Create/list worktrees
    • Allocate/persist ports
    • Copy .env* files
    • Optional dependency installation
  • python scripts/worktree_cleanup.py --help
    • Stale detection by age
    • Dirty-state detection
    • Merged-branch detection
    • Optional safe removal

Both tools support stdin JSON and --input file mode for automation pipelines.

Common Pitfalls

  1. Creating worktrees inside the main repo directory
  2. Reusing localhost:3000 across all branches
  3. Sharing one database URL across isolated feature branches
  4. Removing a worktree with uncommitted changes
  5. Forgetting to prune old metadata after branch deletion
  6. Assuming merged status without checking against the target branch

Best Practices

  1. One branch per worktree, one agent per worktree.
  2. Keep worktrees short-lived; remove after merge.
  3. Use a deterministic naming pattern (wt-<topic>).
  4. Persist port mappings in file, not memory or terminal notes.
  5. Run cleanup scan weekly in active repos.
  6. Use --format json for machine flows and --format text for human review.
  7. Never force-remove dirty worktrees unless changes are intentionally discarded.

Validation Checklist

Before claiming setup complete:

  1. git worktree list shows expected path + branch.
  2. .worktree-ports.json exists and contains unique ports.
  3. .env files copied successfully (if present in source repo).
  4. Dependency install command exits with code 0 (if enabled).
  5. Cleanup scan reports no unintended stale dirty trees.

References

Decision Matrix

Use this quick selector before creating a new worktree:

  • Need isolated dependencies and server ports -> create a new worktree
  • Need only a quick local diff review -> stay on current tree
  • Need hotfix while feature branch is dirty -> create dedicated hotfix worktree
  • Need ephemeral reproduction branch for bug triage -> create temporary worktree and cleanup same day

Operational Checklist

Before Creation

  1. Confirm main repo has clean baseline or intentional WIP commits.
  2. Confirm target branch naming convention.
  3. Confirm required base branch exists (main/develop).
  4. Confirm no reserved local ports are already occupied by non-repo services.

After Creation

  1. Verify git status branch matches expected branch.
  2. Verify .worktree-ports.json exists.
  3. Verify app boots on allocated app port.
  4. Verify DB and cache endpoints target isolated ports.

Before Removal

  1. Verify branch has upstream and is merged when intended.
  2. Verify no uncommitted files remain.
  3. Verify no running containers/processes depend on this worktree path.

CI and Team Integration

  • Use worktree path naming that maps to task ID (wt-1234-auth).
  • Include the worktree path in terminal title to avoid wrong-window commits.
  • In automated setups, persist creation metadata in CI artifacts/logs.
  • Trigger cleanup report in scheduled jobs and post summary to team channel.

Failure Recovery

  • If git worktree add fails due to existing path: inspect path, do not overwrite.
  • If dependency install fails: keep worktree created, mark status and continue manual recovery.
  • If env copy fails: continue with warning and explicit missing file list.
  • If port allocation collides with external service: rerun with adjusted base ports.

senior-architect

alirezarezvani

Comprehensive software architecture skill for designing scalable, maintainable systems using ReactJS, NextJS, NodeJS, Express, React Native, Swift, Kotlin, Flutter, Postgres, GraphQL, Go, Python. Includes architecture diagram generation, system design patterns, tech stack decision frameworks, and dependency analysis. Use when designing system architecture, making technical decisions, creating architecture diagrams, evaluating trade-offs, or defining integration patterns.

170129

content-creator

alirezarezvani

Create SEO-optimized marketing content with consistent brand voice. Includes brand voice analyzer, SEO optimizer, content frameworks, and social media templates. Use when writing blog posts, creating social media content, analyzing brand voice, optimizing SEO, planning content calendars, or when user mentions content creation, brand voice, SEO optimization, social media marketing, or content strategy.

11619

cold-email

alirezarezvani

When the user wants to write, improve, or build a sequence of B2B cold outreach emails to prospects who haven't asked to hear from them. Use when the user mentions 'cold email,' 'cold outreach,' 'prospecting emails,' 'SDR emails,' 'sales emails,' 'first touch email,' 'follow-up sequence,' or 'email prospecting.' Also use when they share an email draft that sounds too sales-y and needs to be humanized. Distinct from email-sequence (lifecycle/nurture to opted-in subscribers) — this is unsolicited outreach to new prospects. NOT for lifecycle emails, newsletters, or drip campaigns (use email-sequence).

3713

content-trend-researcher

alirezarezvani

Advanced content and topic research skill that analyzes trends across Google Analytics, Google Trends, Substack, Medium, Reddit, LinkedIn, X, blogs, podcasts, and YouTube to generate data-driven article outlines based on user intent analysis

10913

ceo-advisor

alirezarezvani

Executive leadership guidance for strategic decision-making, organizational development, and stakeholder management. Includes strategy analyzer, financial scenario modeling, board governance frameworks, and investor relations playbooks. Use when planning strategy, preparing board presentations, managing investors, developing organizational culture, making executive decisions, or when user mentions CEO, strategic planning, board meetings, investor updates, organizational leadership, or executive strategy.

8413

content-humanizer

alirezarezvani

Makes AI-generated content sound genuinely human — not just cleaned up, but alive. Use when content feels robotic, uses too many AI clichés, lacks personality, or reads like it was written by committee. Triggers: 'this sounds like AI', 'make it more human', 'add personality', 'it feels generic', 'sounds robotic', 'fix AI writing', 'inject our voice'. NOT for initial content creation (use content-production). NOT for SEO optimization (use content-production Mode 3).

359

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

642969

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

590705

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

318398

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

339397

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

451339

fastapi-templates

wshobson

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.

304231

Stay ahead of the MCP ecosystem

Get weekly updates on new skills and servers.