New: Earn 20% as an AgentAlley affiliate. Share your link and earn on every sale you refer. Join now New: Earn 20% as an affiliate. Join now

Run parallel feature work safely with Git worktrees

Git worktree manager

by alirezarezvani · MIT license · ★ 26,349 on GitHub · updated Aug 30

Git worktree manager cover

Run parallel feature work safely with Git worktrees. Standardizes branch isolation, port allocation, environment sync, and cleanup so each worktree behaves like an independent local app.

---
name: "git-worktree-manager"
description: "Run parallel feature work safely with Git worktrees. Standardizes branch isolation, port allocation, environment sync, and cleanup so each worktree behaves like an independent local app. Optimized for multi-agent workflows where each agent or terminal session owns one worktree. Use when running multiple feature branches simultaneously, isolating experimental work, or coordinating multi-agent development across the same repo."
---

# 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

Overview

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

Manual install (npx, ZIP)
Claude Codenpx skills add alirezarezvani/claude-skills --skill git-worktree-manager -g -a claude-code
Claude Code (manual)mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/alirezarezvani/claude-skills/tar.gz/19392f7a0826 \ | tar -xz -C ~/.claude/skills --strip-components=3 claude-skills-19392f7a0826/engineering/skills/git-worktree-manager
Windows (PowerShell)New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/b047de5392666e1afdca/git-worktree-manager.zip" -OutFile "$env:TEMP\git-worktree-manager.zip"; Expand-Archive "$env:TEMP\git-worktree-manager.zip" -DestinationPath "$HOME\.claude\skills" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md6.9 KB
  • README.md1.3 KB
  • references/2 files · 2.1 KB
  • scripts/2 files · 14.8 KB
Read the files here
alirezarezvani/19392f76 files
SKILL.md
Show the full text194 lines

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.
1---
2name: "git-worktree-manager"
3description: "Run parallel feature work safely with Git worktrees. Standardizes branch isolation, port allocation, environment sync, and cleanup so each worktree behaves like an independent local app. Optimized for multi-agent workflows where each agent or terminal session owns one worktree. Use when running multiple feature branches simultaneously, isolating experimental work, or coordinating multi-agent development across the same repo."
4---
5 
6# Git Worktree Manager
7 
8**Tier:** POWERFUL
9**Category:** Engineering
10**Domain:** Parallel Development & Branch Isolation
11 
12## Overview
13 
14Use 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.
15 
16This skill is optimized for multi-agent workflows where each agent or terminal session owns one worktree.
17 
18## Core Capabilities
19 
20- Create worktrees from new or existing branches with deterministic naming
21- Auto-allocate non-conflicting ports per worktree and persist assignments
22- Copy local environment files (`.env*`) from main repo to new worktree
23- Optionally install dependencies based on lockfile detection
24- Detect stale worktrees and uncommitted changes before cleanup
25- Identify merged branches and safely remove outdated worktrees
26 
27## When to Use
28 
29- You need 2+ concurrent branches open locally
30- You want isolated dev servers for feature, hotfix, and PR validation
31- You are working with multiple agents that must not share a branch
32- Your current branch is blocked but you need to ship a quick fix now
33- You want repeatable cleanup instead of ad-hoc `rm -rf` operations
34 
35## Key Workflows
36 
37### 1. Create a Fully-Prepared Worktree
38 
391. Pick a branch name and worktree name.
402. Run the manager script (creates branch if missing).
413. Review generated port map.
424. Start app using allocated ports.
43 
44```bash
45python scripts/worktree_manager.py \
46 --repo . \
47 --branch feature/new-auth \
48 --name wt-auth \
49 --base-branch main \
50 --install-deps \
51 --format text
52```
53 
54If you use JSON automation input:
55 
56```bash
57cat config.json | python scripts/worktree_manager.py --format json
58# or
59python scripts/worktree_manager.py --input config.json --format json
60```
61 
62### 2. Run Parallel Sessions
63 
64Recommended convention:
65 
66- Main repo: integration branch (`main`/`develop`) on default port
67- Worktree A: feature branch + offset ports
68- Worktree B: hotfix branch + next offset
69 
70Each worktree contains `.worktree-ports.json` with assigned ports.
71 
72### 3. Cleanup with Safety Checks
73 
741. Scan all worktrees and stale age.
752. Inspect dirty trees and branch merge status.
763. Remove only merged + clean worktrees, or force explicitly.
77 
78```bash
79python scripts/worktree_cleanup.py --repo . --stale-days 14 --format text
80python scripts/worktree_cleanup.py --repo . --remove-merged --format text
81```
82 
83### 4. Docker Compose Pattern
84 
85Use per-worktree override files mapped from allocated ports. The script outputs a deterministic port map; apply it to `docker-compose.worktree.yml`.
86 
87See [docker-compose-patterns.md](references/docker-compose-patterns.md) for concrete templates.
88 
89### 5. Port Allocation Strategy
90 
91Default strategy is `base + (index * stride)` with collision checks:
92 
93- App: `3000`
94- Postgres: `5432`
95- Redis: `6379`
96- Stride: `10`
97 
98See [port-allocation-strategy.md](references/port-allocation-strategy.md) for the full strategy and edge cases.
99 
100## Script Interfaces
101 
102- `python scripts/worktree_manager.py --help`
103 - Create/list worktrees
104 - Allocate/persist ports
105 - Copy `.env*` files
106 - Optional dependency installation
107- `python scripts/worktree_cleanup.py --help`
108 - Stale detection by age
109 - Dirty-state detection
110 - Merged-branch detection
111 - Optional safe removal
112 
113Both tools support stdin JSON and `--input` file mode for automation pipelines.
114 
115## Common Pitfalls
116 
1171. Creating worktrees inside the main repo directory
1182. Reusing `localhost:3000` across all branches
1193. Sharing one database URL across isolated feature branches
1204. Removing a worktree with uncommitted changes
1215. Forgetting to prune old metadata after branch deletion
1226. Assuming merged status without checking against the target branch
123 
124## Best Practices
125 
1261. One branch per worktree, one agent per worktree.
1272. Keep worktrees short-lived; remove after merge.
1283. Use a deterministic naming pattern (`wt-<topic>`).
1294. Persist port mappings in file, not memory or terminal notes.
1305. Run cleanup scan weekly in active repos.
1316. Use `--format json` for machine flows and `--format text` for human review.
1327. Never force-remove dirty worktrees unless changes are intentionally discarded.
133 
134## Validation Checklist
135 
136Before claiming setup complete:
137 
1381. `git worktree list` shows expected path + branch.
1392. `.worktree-ports.json` exists and contains unique ports.
1403. `.env` files copied successfully (if present in source repo).
1414. Dependency install command exits with code `0` (if enabled).
1425. Cleanup scan reports no unintended stale dirty trees.
143 
144## References
145 
146- [port-allocation-strategy.md](references/port-allocation-strategy.md)
147- [docker-compose-patterns.md](references/docker-compose-patterns.md)
148- [README.md](README.md) for quick start and installation details
149 
150## Decision Matrix
151 
152Use this quick selector before creating a new worktree:
153 
154- Need isolated dependencies and server ports -> create a new worktree
155- Need only a quick local diff review -> stay on current tree
156- Need hotfix while feature branch is dirty -> create dedicated hotfix worktree
157- Need ephemeral reproduction branch for bug triage -> create temporary worktree and cleanup same day
158 
159## Operational Checklist
160 
161### Before Creation
162 
1631. Confirm main repo has clean baseline or intentional WIP commits.
1642. Confirm target branch naming convention.
1653. Confirm required base branch exists (`main`/`develop`).
1664. Confirm no reserved local ports are already occupied by non-repo services.
167 
168### After Creation
169 
1701. Verify `git status` branch matches expected branch.
1712. Verify `.worktree-ports.json` exists.
1723. Verify app boots on allocated app port.
1734. Verify DB and cache endpoints target isolated ports.
174 
175### Before Removal
176 
1771. Verify branch has upstream and is merged when intended.
1782. Verify no uncommitted files remain.
1793. Verify no running containers/processes depend on this worktree path.
180 
181## CI and Team Integration
182 
183- Use worktree path naming that maps to task ID (`wt-1234-auth`).
184- Include the worktree path in terminal title to avoid wrong-window commits.
185- In automated setups, persist creation metadata in CI artifacts/logs.
186- Trigger cleanup report in scheduled jobs and post summary to team channel.
187 
188## Failure Recovery
189 
190- If `git worktree add` fails due to existing path: inspect path, do not overwrite.
191- If dependency install fails: keep worktree created, mark status and continue manual recovery.
192- If env copy fails: continue with warning and explicit missing file list.
193- If port allocation collides with external service: rerun with adjusted base ports.
194 
View all files on GitHub →

Details

Updated
Aug 30, 2026
License
MIT
Stars on the repo
★ 26,349
Checked
Source
alirezarezvani/claude-skills ↗
Creator
alirezarezvani · 363 listings
View creator

Similar skills

See all →
SkillAutomates CI/CD pipeline setupCI/CD and Automationaddyosmani/agent-skills · by addyosmaniAutomates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.★ 98.7k GitHub starsSkillAutomated semantic versioning and release workflowVersion Bump & Release Workflowthedotmack/claude-mem · by thedotmackAutomated semantic versioning and release workflow for Claude Code plugins. Handles version increments across package.json, marketplace.json, plugin.json manifests, build verification, git tagging, GitHub releases, and changelog generation. NPM publishing is the final human-required handoff because the maintainer raised npm security.★ 95.6k GitHub starsSkillOperate Orca-managed worktrees, folder contexts, terminalsOrca CLIstablyai/orca · by stablyaiOperate Orca-managed worktrees, folder contexts, terminals, repos, automations, artifacts, skill sharing, worktree comments, and Orca's embedded browser through the `orca` CLI. Use when the user says "$orca-cli", "Orca worktree", "child worktree", "spawn codex/claude in a worktree", "read/wait/send Orca terminal", "handoff" / "handover" / "give this to another agent", "Orca browser", "orca artifacts", or "share skills". Prefer it over raw git worktree, ad hoc PTYs, or Computer Use when Orca state is involved. Use Computer Use only when a visible window needs GUI control that a CLI, filesystem, or API cannot do.★ 84.5k GitHub starsSkillThreaded messages, blocking ask/reply, task dispatchOrca Orchestrationstablyai/orca · by stablyaiCoordinate supervised Orca workers: threaded messages, blocking ask/reply, task dispatch, worker_done/escalation waits, task DAGs, decision gates, coordinator loops, and decomposing work across agents. Use `orca-cli` for full ownership handoffs — "hand off", "handoff", "handover", "give this to another agent", "another worktree" — unless asked to supervise, monitor, or coordinate a DAG, and for terminal control, lightweight terminal prompts, shell commands, Orca worktree management, and reading or waiting on terminals.★ 84.5k GitHub starsSkillDeploy applications and websites to VercelVercel deploybytedance/deer-flow · by bytedanceDeploy applications and websites to Vercel. Use this skill when the user requests deployment actions such as "Deploy my app", "Deploy this to production", "Create a preview deployment", "Deploy and give me the link", or "Push this live". No authentication required - returns preview URL and claimable deployment link.★ 83.5k GitHub starsSkillOpen or update a pull request on pascalorg/editorOpen PRpascalorg/editor · by pascalorgOpen or update a pull request on pascalorg/editor from the current branch, describing only what the branch actually did. Use when the user asks to open/create a PR, push and PR, or ship a branch in the editor repo.★ 24.6k GitHub stars

More from alirezarezvani

SkillResume a paused experiment/ar:ar-resume — Resume Experimentalirezarezvani/claude-skills · by alirezarezvaniResume a paused experiment. Checkout the experiment branch, read results history, continue iterating. Use when the user runs /ar:ar-resume or asks to pick up a previously started autoresearch experiment.★ 26.3k GitHub starsSkillShow experiment dashboard with results, active loops/ar:ar-status — Experiment Dashboardalirezarezvani/claude-skills · by alirezarezvaniShow experiment dashboard with results, active loops, and progress. Use when the user runs /ar:ar-status or asks how an autoresearch experiment is going.★ 26.3k GitHub starsSkillStart an autonomous experiment loop with user-selected/ar:loop — Autonomous Experiment Loopalirezarezvani/claude-skills · by alirezarezvaniStart an autonomous experiment loop with user-selected interval (10min, 1h, daily, weekly, monthly). Uses CronCreate for scheduling. Use when the user runs /ar:loop or asks to run an autoresearch experiment continuously on a schedule.★ 26.3k GitHub starsSkillRun a single experiment iteration/ar:run — Single Experiment Iterationalirezarezvani/claude-skills · by alirezarezvaniRun a single experiment iteration. Edit the target file, evaluate, keep or discard. Use when the user runs /ar:run or asks for one manual autoresearch iteration.★ 26.3k GitHub starsSkillSet up a new autoresearch experiment interactively/ar:setup — Create New Experimentalirezarezvani/claude-skills · by alirezarezvaniSet up a new autoresearch experiment interactively. Collects domain, target file, eval command, metric, direction, and evaluator. Use when the user runs /ar:setup or asks to start optimizing a file with the autoresearch loop.★ 26.3k GitHub starsSkill/cs:boardroom <brief/cs:boardroom — Multi-Role Boardroom Deliberationalirezarezvani/claude-skills · by alirezarezvani/cs:boardroom <brief> — 6-phase multi-role deliberation across the C-suite with Phase 2 isolation, critic pre-screen, and synthesis. Outputs a board memo. Use when a decision spans multiple executive domains — e.g. a pricing change touching finance, positioning, and product, or a raise-vs-cut runway call.★ 26.3k GitHub stars