---
name: git-worktree-parallel-workflow
description: "Sets up and later cleans up git worktrees so several branches can be developed side by side with no stashing or branch switching. Use when several branches must be worked on at once and stashing or switching in one checkout is getting in the way. Do not use for resolving merge conflicts or deciding how to merge a finished branch. Related topics: coding, devops."
---

# Git Worktree Parallel Workflow

Sets up and later cleans up git worktrees so several branches can be developed side by side with no stashing or branch switching.

## When to use

Use this skill when several branches must be worked on at once and stashing or switching in one checkout is getting in the way. Do not use it for resolving merge conflicts or deciding how to merge a finished branch.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Inspect the main checkout state and the base branch before creating anything.
3. Create one worktree per branch in the chosen folder, outside any tracked path, with clear names.
4. List per-tree setup needs such as dependency installs when a build step is required.
5. For status or clean up, report each worktree's branch, state and merged status before removing anything.
6. Remove only merged or abandoned trees after confirming nothing uncommitted would be lost, then prune.

## Inputs

- **Repository path** (free text, e.g. "Path of the main checkout")
- **Branches needed** (longer free text)
- **Base branch** (free text, e.g. "main or develop")
- **Where worktrees live** (free text, e.g. "A folder outside the repository")
- **Phase** (choose one: Set up, Check status, Clean up)
- **Project needs a build step per tree** (choose one: Yes, No)

## Output

An ordered list of exact git commands for the chosen phase, with destructive ones flagged and a short status table of worktrees.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Git Worktree Parallel Workflow

Set up git worktrees for the parallel work I describe, and clean them up afterwards.

- Repository path: {{Repository path}}
- Branches needed: {{Branches needed}}
- Base branch: {{Base branch}}
- Where worktrees live: {{Where worktrees live}}
- Phase: {{Phase}}
- Project needs a build step per tree: {{Project needs a build step per tree}}

For set up, create each worktree from the base branch in the chosen folder, one per branch, with a clear folder name, and never touch uncommitted work in the main checkout. Check the folder is ignored or outside the repo so it cannot be committed. When a build step is needed, list what each tree must install or generate. For status, list each worktree with its branch, clean or dirty state and whether it is merged. For clean up, remove only worktrees whose branches are merged or explicitly abandoned, confirm that nothing uncommitted would be lost, then prune stale entries and delete merged branches. Print the exact commands in order, and mark any that are destructive.

## Pitfalls

- Creating worktrees inside the repository folder, where their files show up as untracked changes.
- Removing a worktree that holds uncommitted work, which loses it for good.
- Checking the same branch out in two trees, which git refuses and confuses people.
