$npx -y skills add krzysztofsurdy/code-virtuoso --skill worktree-opsManage git worktrees for isolated parallel development sessions. Create, list, switch between, and remove worktrees with safety checks for uncommitted changes and unpushed commits. Use when the user wants to work on multiple branches simultaneously, run parallel sessions, or isol
| 1 | # Worktree Management |
| 2 | |
| 3 | Git worktrees let you check out multiple branches of the same repository into separate directories simultaneously. Each worktree has its own working directory and index while sharing the same `.git` object store and history. This is useful for running parallel development sessions, reviewing a PR while mid-feature, or isolating experimental changes without stashing or committing half-finished work. |
| 4 | |
| 5 | ## Core Principles |
| 6 | |
| 7 | | Principle | Meaning | |
| 8 | |---|---| |
| 9 | | **Isolation without duplication** | Worktrees share git history but keep working directories separate - no need to clone the repo again | |
| 10 | | **Safety first** | Always check for uncommitted changes and unpushed commits before removing a worktree | |
| 11 | | **Clean up after yourself** | Stale worktree entries and orphaned branches accumulate - prune regularly | |
| 12 | | **Convention over configuration** | Use a consistent directory layout (`.worktrees/<name>/`) and branch naming (`worktree-<name>`) | |
| 13 | |
| 14 | ## Quick Reference |
| 15 | |
| 16 | | Command | What it does | When to use | |
| 17 | |---|---|---| |
| 18 | | `git worktree add <path> -b <branch>` | Create a new worktree with a new branch | Starting parallel work on a new task | |
| 19 | | `git worktree list` | Show all worktrees with their branches and paths | Checking what is active | |
| 20 | | `git worktree list --porcelain` | Machine-readable worktree listing | Scripting or enriching with status info | |
| 21 | | `git worktree remove <path>` | Remove a worktree directory and its admin files | Done with a parallel task | |
| 22 | | `git worktree remove <path> --force` | Force-remove even with uncommitted changes | After explicit user confirmation | |
| 23 | | `git worktree prune` | Clean up stale worktree entries | After manual directory deletion or errors | |
| 24 | | `git branch -D worktree-<name>` | Delete the orphaned branch after worktree removal | Keeping branches clean | |
| 25 | |
| 26 | ## Create |
| 27 | |
| 28 | Create a new worktree for an isolated parallel development session. |
| 29 | |
| 30 | ### Workflow |
| 31 | |
| 32 | 1. Confirm the current directory is a git repository. |
| 33 | 2. Confirm the current session is NOT already inside a worktree: |
| 34 | ```bash |
| 35 | git rev-parse --is-inside-work-tree && git worktree list |
| 36 | ``` |
| 37 | If the current working directory is already a worktree (not the main working tree), warn the user and stop. |
| 38 | 3. If a name was provided as an argument, use it. Otherwise, present an interactive prompt (or the platform's equivalent): "What name should I use for this worktree? (e.g., `feature-auth`, `bugfix-123`)" |
| 39 | 4. Create the worktree: |
| 40 | ```bash |
| 41 | git worktree add .worktrees/<name> -b worktree-<name> |
| 42 | ``` |
| 43 | 5. Change your working directory to the new worktree path. |
| 44 | 6. Report to the user: |
| 45 | ``` |
| 46 | Worktree created: |
| 47 | Directory: .worktrees/<name>/ |
| 48 | Branch: worktree-<name> |
| 49 | Based on: <current HEAD> |
| 50 | ``` |
| 51 | 7. Remind the user: |
| 52 | - Run your stack's dependency installation command (e.g., `composer install`, `npm install`, `pip install -r requirements.txt`) |
| 53 | - The worktree shares git history with the main repo but has its own working directory |
| 54 | - Use the `list` command to see all active worktrees |
| 55 | - Use the `remove` command to clean up when done |
| 56 | |
| 57 | ## List |
| 58 | |
| 59 | List all active worktrees with their branches, paths, and status. |
| 60 | |
| 61 | ### Workflow |
| 62 | |
| 63 | 1. Confirm the current directory is inside a git repository. |
| 64 | 2. Run: |
| 65 | ```bash |
| 66 | git worktree list --porcelain |
| 67 | ``` |
| 68 | 3. For each worktree, gather uncommitted change count: |
| 69 | ```bash |
| 70 | git -C <worktree-path> status --short 2>/dev/null |
| 71 | ``` |
| 72 | 4. Display a clean table: |
| 73 | ``` |
| 74 | Active worktrees: |
| 75 | |
| 76 | | # | Name | Branch | Path | Status | |
| 77 | |---|--------------|----------------------|-------------------------------|---------------| |
| 78 | | 1 | (main) | main | /path/to/repo | clean | |
| 79 | | 2 | feature-auth | worktree-feature-auth| .worktrees/feature-auth | 3 uncommitted | |
| 80 | | 3 | bugfix-123 | worktree-bugfix-123 | .worktrees/bugfix-123 | clean | |
| 81 | ``` |
| 82 | 5. If no worktrees exist beyond the main working tree, say: "No additional worktrees found. Use the `create` command to create one." |
| 83 | |
| 84 | ## Switch |
| 85 | |
| 86 | Switch your working directory to a different existing worktree. |
| 87 | |
| 88 | ### Workflow |
| 89 | |
| 90 | 1. Confirm the current directory is inside a git repository. |
| 91 | 2. Run: |
| 92 | ```bash |
| 93 | git worktree list |
| 94 | ``` |
| 95 | If only the main working tree exists, say: "No worktrees available to switch to. Use the `create` command to create one." and stop. |
| 96 | 3. If a name was provided as an argument, find the matching worktree path. Otherwise, show the list and prese |