Git Worktree Manager
Tier: POWERFUL
Category: Engineering
Domain: Parallel Development & Branch Isolation
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.
.env*) from main repo to new worktreerm -rf operationspython 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
Recommended convention:
main/develop) on default portEach worktree contains .worktree-ports.json with assigned ports.
python scripts/worktree_cleanup.py --repo . --stale-days 14 --format text
python scripts/worktree_cleanup.py --repo . --remove-merged --format text
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.
Default strategy is base + (index * stride) with collision checks:
30005432637910See port-allocation-strategy.md for the full strategy and edge cases.
python scripts/worktree_manager.py --help
.env* filespython scripts/worktree_cleanup.py --help
Both tools support stdin JSON and --input file mode for automation pipelines.
localhost:3000 across all brancheswt-<topic>).--format json for machine flows and --format text for human review.Before claiming setup complete:
git worktree list shows expected path + branch..worktree-ports.json exists and contains unique ports..env files copied successfully (if present in source repo).0 (if enabled).Use this quick selector before creating a new worktree:
main/develop).git status branch matches expected branch..worktree-ports.json exists.wt-1234-auth).git worktree add fails due to existing path: inspect path, do not overwrite.