This skill should be used when the user wants to manage Git worktrees - creating worktrees from local or remote branches, listing active worktrees with details, deleting worktrees, or switching...
This skill provides comprehensive Git worktree management capabilities, enabling work on multiple branches simultaneously in isolated directories. Worktrees eliminate the need for stashing when switching contexts and are ideal for parallel development, quick bug fixes, and code reviews.
Use this skill when the user wants to:
Location Strategy: Sibling directory pattern
../<project>-<branch>~/dev/myproject, worktree at ~/dev/myproject-feature-xNaming Convention: <project>-<branch>
basename "$(git rev-parse --show-toplevel)"myproject-feature-auth, myapp-bugfix-loginHybrid Mode: Accepts arguments when provided, prompts when missing
Usage patterns:
# Interactive menu
User: "Manage my worktrees"
User: "Create a worktree"
# Direct with arguments
User: "Create worktree from remote branch feature-x"
User: "List all worktrees"
User: "Delete worktree for branch hotfix-123"
Purpose: Show all active worktrees with detailed information
What to display:
Implementation:
# Get project name
project=$(basename "$(git rev-parse --show-toplevel)")
# List worktrees with details
git worktree list -v
Output format:
Git Worktrees for myproject:
1. /Users/dev/myproject (main)
abc1234 Initial commit
[CURRENT]
2. /Users/dev/myproject-feature-x (feature-x)
def5678 Add authentication logic
3. /Users/dev/myproject-hotfix (hotfix-123)
789abcd Fix login bug
Purpose: Fetch and create a worktree from a remote branch
Steps:
project=$(basename "$(git rev-parse --show-toplevel)")origin/feature-x → feature-x)git fetch origin <branch-name>../<project>-<branch-name>git worktree add ../<project>-<branch-name> origin/<branch-name>Error handling:
Success output:
✓ Created worktree for remote branch 'feature-x'
Location: /Users/dev/myproject-feature-x
Branch: feature-x (tracking origin/feature-x)
To switch to this worktree:
cd ../myproject-feature-x
To start working:
cd ../myproject-feature-x && code .
Purpose: Create a worktree from an existing local branch
Steps:
git rev-parse --verify <branch-name>git worktree add ../<project>-<branch-name> <branch-name>Error handling:
Purpose: Create a worktree with a brand new branch
Parameters needed:
Steps:
git worktree add -b <new-branch> ../<project>-<new-branch> <base-branch>Success output:
✓ Created new worktree with branch 'experiment-auth'
Location: /Users/dev/myproject-experiment-auth
Branch: experiment-auth (based on main)
To switch to this worktree:
cd ../myproject-experiment-auth
Purpose: Remove a worktree and show prune command
Steps:
git worktree remove <path> or manually rm -rf <path>Output:
✓ Removed worktree at /Users/dev/myproject-feature-x
To clean up metadata, run:
git worktree prune
Purpose: Clean up worktree metadata
Steps:
git worktree pruneOutput:
✓ Pruned stale worktree metadata
Run 'git worktree list' to see remaining worktrees.
Purpose: Show easy navigation to worktrees
Implementation:
Output:
Available worktrees:
1. main (current)
cd /Users/dev/myproject
2. feature-x
cd /Users/dev/myproject-feature-x
3. hotfix-123
cd /Users/dev/myproject-hotfix
When invoked without arguments:
Show menu:
Git Worktree Management
1. List all worktrees
2. Create from remote branch
3. Create from local branch
4. Create new branch
5. Delete worktree
6. Prune metadata
7. Switch between worktrees
Prompt for selection
For create operations, prompt for required info (branch name, base branch, etc.)
Execute operation
Show results with clear next steps
When arguments are provided, parse intent:
Before any operation:
git rev-parse --git-dir