Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
alirezarezvani avatar

Git Worktree Manager

  • 560 installs
  • 23.5k repo stars
  • Updated July 17, 2026
  • alirezarezvani/claude-skills

git-worktree-manager is an agent skill with Python CLI scripts that create isolated git worktrees with deterministic ports, synced .env files, and safe stale-worktree cleanup for parallel feature development.

About

git-worktree-manager is a production workflow skill from alirezarezvani/claude-skills for parallel branch development using git worktrees. It ships two Python scripts—worktree_manager.py for create/list-prep with deterministic ports, .env* sync, and optional dependency install, and worktree_cleanup.py for stale worktree review with a configurable stale-days threshold (default example: 14 days). Developers run commands like `python scripts/worktree_manager.py --repo . --branch feature/api-hardening --install-deps` to spin up isolated environments without port collisions. Reach for this skill when juggling multiple features, agent sessions, or PR branches that each need their own checkout, env, and dev server port.

  • worktree_manager.py:create, list-prep, deterministic port assignment, .env* sync, optional dependency install
  • worktree_cleanup.py: stale, dirty, and merged analysis with optional safe removal after configurable stale days
  • JSON stdin/--input automation interfaces on both scripts for agent pipelines
  • Reference docs for port-allocation strategy and per-worktree Docker Compose override patterns
  • Install paths documented for Claude Code, Codex, and OpenClaw skill directories

Git Worktree Manager by the numbers

  • 560 all-time installs (skills.sh)
  • Ranked #102 of 735 Git & Pull Requests skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Jul 31, 2026 (Skillselion catalog sync)
npx skills add https://github.com/alirezarezvani/claude-skills --skill git-worktree-manager

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs560
repo stars23.5k
Security audit3 / 3 scanners passed
Last updatedJuly 17, 2026
Repositoryalirezarezvani/claude-skills

How do you run parallel git worktrees with isolated ports?

Spin up isolated git worktrees with deterministic ports, synced env files, and safe stale-worktree cleanup while juggling parallel features.

Who is it for?

Developers running multiple feature branches or agent sessions who need isolated worktrees, env sync, and port assignment without manual git plumbing.

Skip if: Teams that only use a single branch checkout or rely on container-based isolation instead of native git worktrees.

When should I use this skill?

The developer needs parallel branch checkouts with env sync, port assignment, or cleanup of stale git worktrees.

What you get

Prepared git worktree, synced .env files, assigned dev port, stale-worktree cleanup report, and branch-isolated checkout.

  • isolated worktree
  • synced env files
  • stale worktree report

By the numbers

  • Bundles 2 Python scripts: worktree_manager.py and worktree_cleanup.py
  • Documents --stale-days 14 as example stale-worktree threshold

Files

SKILL.mdMarkdownGitHub ↗

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

  • port-allocation-strategy.md
  • docker-compose-patterns.md
  • README.md for quick start and installation details

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.

Related skills

How it compares

Pick git-worktree-manager over generic git skills when you need scripted port assignment, env sync, and stale cleanup—not just basic worktree commands.

FAQ

What scripts does git-worktree-manager include?

git-worktree-manager bundles worktree_manager.py for create/list-prep with deterministic ports and .env* sync, plus worktree_cleanup.py for reviewing and removing stale worktrees by age threshold.

How does git-worktree-manager avoid port conflicts?

git-worktree-manager assigns deterministic ports during worktree creation via worktree_manager.py, so each parallel branch checkout can run its own dev server without manual port hunting.

Is Git Worktree Manager safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.