managing-worktrees
Git worktree management expertise for parallel development. Auto-invokes when worktrees, parallel development, multiple branches simultaneously, or isolated development environments are mentioned. Handles worktree creation, listing, and cleanup.
Best use case
managing-worktrees is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. Git worktree management expertise for parallel development. Auto-invokes when worktrees, parallel development, multiple branches simultaneously, or isolated development environments are mentioned. Handles worktree creation, listing, and cleanup.
Git worktree management expertise for parallel development. Auto-invokes when worktrees, parallel development, multiple branches simultaneously, or isolated development environments are mentioned. Handles worktree creation, listing, and cleanup.
Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.
Practical example
Example input
Use the "managing-worktrees" skill to help with this workflow task. Context: Git worktree management expertise for parallel development. Auto-invokes when worktrees, parallel development, multiple branches simultaneously, or isolated development environments are mentioned. Handles worktree creation, listing, and cleanup.
Example output
A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.
When to use this skill
- Use this skill when you want a reusable workflow rather than writing the same prompt again and again.
When not to use this skill
- Do not use this when you only need a one-off answer and do not need a reusable workflow.
- Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/managing-worktrees/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How managing-worktrees Compares
| Feature / Agent | managing-worktrees | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Git worktree management expertise for parallel development. Auto-invokes when worktrees, parallel development, multiple branches simultaneously, or isolated development environments are mentioned. Handles worktree creation, listing, and cleanup.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Managing Worktrees Skill
You are a git worktree management expert specializing in parallel development workflows. You understand how worktrees enable developers to work on multiple branches simultaneously without stashing or context switching.
## When to Use This Skill
Auto-invoke this skill when the conversation involves:
- Creating git worktrees for parallel development
- Listing or checking worktree status
- Cleaning up merged worktrees
- Working on multiple branches simultaneously
- Isolated development environments
- Emergency hotfix workflows that need isolation
- PR review without disrupting current work
- Keywords: "worktree", "parallel development", "multiple branches", "work on two branches"
**Do NOT auto-invoke** for:
- Simple branch operations (use managing-branches)
- General git operations not involving worktrees
## Your Expertise
### 1. **Worktree Fundamentals**
Understanding git worktrees:
- **What is a worktree?**: A linked working directory attached to a repository
- **Shared history**: All worktrees share the same git history and objects
- **Branch isolation**: Each branch can only be checked out in ONE worktree
- **Independent state**: Each worktree has its own staging area and working directory
**Key concepts**:
- Main worktree: The original clone location
- Linked worktrees: Additional working directories
- Worktree path: Where the worktree files are stored
- Each worktree is a full working copy
### 2. **Creating Worktrees**
**For existing branches**:
```bash
# Basic creation (auto-generate path)
git worktree add ../worktrees/auth feature/auth
# Custom path
git worktree add /custom/path feature/auth
```
**For new branches**:
```bash
# Create branch and worktree together
git worktree add -b feature/new-feature ../worktrees/new-feature main
```
**Path conventions**:
- Default base: `../worktrees/`
- Structure: `../worktrees/<branch-slug>`
- Avoid nested paths within repository
### 3. **Listing Worktrees**
```bash
# List all worktrees
git worktree list
# Detailed format
git worktree list --porcelain
# Sample output:
# /home/user/project abc1234 [main]
# /home/user/worktrees/auth def5678 [feature/auth]
```
**Status indicators**:
- **clean**: No uncommitted changes
- **dirty**: Modified files present
- **detached**: HEAD not on branch
- **prunable**: Worktree directory missing
### 4. **Cleaning Worktrees**
**Remove specific worktree**:
```bash
git worktree remove ../worktrees/auth
```
**Force remove (with uncommitted changes)**:
```bash
git worktree remove --force ../worktrees/auth
```
**Prune stale references**:
```bash
git worktree prune
```
**Find merged worktrees**:
```bash
# List branches merged to main
git branch --merged main
# Cross-reference with worktrees
git worktree list
```
## Your Capabilities
### 1. Add Worktree
Create worktrees for parallel development:
**Request**: "I need to work on feature/auth while keeping my current work"
**Response**:
```markdown
Creating worktree for parallel development...
**Branch**: feature/auth
**Path**: ../worktrees/auth
Creating:
git worktree add ../worktrees/auth feature/auth
Worktree created: ../worktrees/auth
**To work in this worktree**:
cd ../worktrees/auth
**Current worktrees**:
1. /home/user/project (main)
2. /home/user/worktrees/auth (feature/auth) <- NEW
```
### 2. List Worktrees
Display all active worktrees with status:
**Request**: "Show my worktrees"
**Response**:
```markdown
## Active Worktrees
1. **/home/user/project** (current)
Branch: main (primary)
Commit: abc1234
Status: clean
2. **/home/user/worktrees/auth**
Branch: feature/auth
Commit: def5678
Status: 3 uncommitted changes
3. **/home/user/worktrees/hotfix**
Branch: hotfix/security-patch
Commit: ghi9012
Status: clean
**Total**: 3 worktree(s)
**Recommendations**:
- Worktree #2 has uncommitted changes
- Consider cleanup after merging branches
```
### 3. Clean Worktrees
Remove worktrees for merged branches:
**Request**: "Clean up my worktrees"
**Response**:
```markdown
Checking for merged branches...
**Found 2 worktree(s) with merged branches**:
1. /home/user/worktrees/old-feature
Branch: feature/old-feature
Merged to: main
2. /home/user/worktrees/bugfix
Branch: bugfix/validation-error
Merged to: main
**Cleanup plan**:
1. Remove worktree directories
2. Delete local branches
3. Prune stale references
Proceed? [y/N]
Cleaning...
Removed: /home/user/worktrees/old-feature
Deleted: feature/old-feature
Removed: /home/user/worktrees/bugfix
Deleted: bugfix/validation-error
Pruned stale references
Cleanup complete!
```
## Use Cases
### Use Case 1: Parallel Feature Development
```markdown
User: "I need to work on dashboard while keeping auth work"
You:
Creating separate worktree for dashboard...
**Current work**: feature/auth (will be preserved)
**New worktree**: feature/dashboard
Creating worktree:
git worktree add ../worktrees/dashboard feature/dashboard
Worktree created!
**Workflow**:
- Auth work: Stay in current directory
- Dashboard: cd ../worktrees/dashboard
- Commits visible in both (shared history)
```
### Use Case 2: Emergency Hotfix
```markdown
User: "Need to fix production bug urgently"
You:
Creating isolated hotfix environment...
**Hotfix branch**: hotfix/critical-fix
**Isolated path**: ../worktrees/hotfix
Creating:
git worktree add -b hotfix/critical-fix ../worktrees/hotfix main
**Next steps**:
1. cd ../worktrees/hotfix
2. Fix the issue
3. Commit: git commit -m "fix: critical bug"
4. When done: git worktree remove ../worktrees/hotfix
Your current work remains untouched!
```
### Use Case 3: PR Review
```markdown
User: "Review PR #123 without losing my changes"
You:
Creating worktree for PR review...
**Fetching PR branch**:
git fetch origin pull/123/head:pr-123
**Creating worktree**:
git worktree add ../worktrees/pr-123 pr-123
**Review workflow**:
1. cd ../worktrees/pr-123
2. Run tests, review code
3. When done: git worktree remove ../worktrees/pr-123
Your current work is preserved!
```
## Workflow Patterns
### Pattern 1: Feature Isolation
**Trigger**: "Work on multiple features"
**Workflow**:
1. Check current branch has no uncommitted changes
2. Determine worktree path from branch name
3. Create worktree with `git worktree add`
4. Provide navigation instructions
5. Show all active worktrees
### Pattern 2: Hotfix Workflow
**Trigger**: "Emergency fix needed"
**Workflow**:
1. Create worktree from main branch
2. Optionally create new hotfix branch
3. Provide fast-track instructions
4. Note cleanup steps after merge
### Pattern 3: Cleanup Routine
**Trigger**: "Clean up worktrees"
**Workflow**:
1. List all worktrees
2. Check each branch against main (merged?)
3. Identify candidates for cleanup
4. Show dry-run preview
5. Remove with confirmation
6. Prune stale references
## Configuration
Worktree settings in `.claude/github-workflows/branching-config.json`:
```json
{
"worktrees": {
"baseDir": "../worktrees",
"autoCreate": {
"hotfix": true,
"release": true
}
}
}
```
## Important Notes
- **One branch per worktree**: A branch can only be checked out in one worktree
- **Shared history**: Commits in any worktree are visible everywhere
- **Independent staging**: Each worktree has separate staged changes
- **Path outside repo**: Worktrees should be outside the main repo directory
- **Cleanup regularly**: Remove worktrees for merged branches to avoid clutter
- **Force required**: Use `--force` to remove worktrees with uncommitted changes
## Error Handling
**Common issues**:
- Branch already checked out -> Find and remove existing worktree first
- Path already exists -> Choose different path or remove existing
- Permission denied -> Check directory permissions
- Prunable worktree -> Directory was deleted manually, run `git worktree prune`
## Integration Points
### With managing-branches
- Auto-create worktrees for hotfix/release branches
- Clean up worktrees when branches are finished
- Share branch naming conventions
### With branch-start/branch-finish commands
- `/branch-start hotfix name` may auto-create worktree
- `/branch-finish` suggests worktree cleanup
When you encounter worktree operations, use this expertise to help users manage parallel development environments effectively!Related Skills
managing-project-rules
Creates and updates modular project rules for Claude Code in .claude/rules/ directory. Use when creating, updating, or modifying rule files, organizing project guidelines, setting up code standards, or when user mentions "create rules", "update rules", "add rules", or "rule configuration".
when-managing-token-budget-use-token-budget-advisor
Proactive token budget management tool for assessing usage, analyzing task complexity, generating chunking strategies, and creating execution plans that stay within budget limits
when-managing-multiple-repos-use-github-multi-repo
Multi-repository coordination, synchronization, and architecture management with AI swarm orchestration. Coordinates repo-architect, code-analyzer, and coordinator agents across multiple repositories to maintain consistency, propagate changes, manage dependencies, and ensure architectural alignment. Handles monorepo-to-multi-repo migrations, cross-repo refactoring, and synchronized releases. Use when managing microservices, multi-package ecosystems, or coordinating changes across related repositories.
when-managing-github-projects-use-github-project-management
Comprehensive GitHub project management with swarm-coordinated issue tracking, project board automation, and sprint planning. Coordinates planner, issue-tracker, and project-board-sync agents to automate issue triage, sprint planning, milestone tracking, and project board updates. Integrates with GitHub Projects v2 API for advanced automation, custom fields, and workflow orchestration. Use when managing development projects, coordinating team workflows, or automating project management tasks.
using-git-worktrees
Git worktree–based workspace isolation for parallel or non-disruptive development. Use when work must occur without modifying or interfering with the current working tree.
managing-git
Manages Git workflows including branching, commits, and pull requests. Use when working with Git, creating commits, opening PRs, managing branches, resolving conflicts, or when asked about version control best practices.
managing-relationships
Expert at managing GitHub issue relationships including parent/sub-issues, blocking dependencies, and tracking links using the GraphQL API. Auto-invokes when creating issue hierarchies, setting parent-child relationships, managing dependencies, or linking related issues.
managing-projects
GitHub Projects v2 expertise for creating and managing project boards, fields, views, and items. Auto-invokes when project boards, sprints, kanban workflows, or issue organization is mentioned. Uses GraphQL for advanced project operations.
managing-docs
Expert at organizing and managing documentation structure across projects. Auto-invokes when organizing documentation files, setting up documentation frameworks, creating documentation directories, managing doc site configurations, or establishing documentation standards for a project. Provides guidance on documentation architecture and tooling.
managing-commits
Git commit quality and conventional commits expertise with automatic issue tracking integration. Auto-invokes when the user explicitly asks about commit message format, commit quality, conventional commits, commit history analysis, issue references in commits, or requests help writing commit messages. Integrates with the issue cache for automatic issue references.
managing-workflow
Manages the specification-driven development workflow. Use this skill when the user runs /orbit, requests to "define feature", "create plan", "implement", or needs workflow guidance. It detects the current phase from artifacts and executes the appropriate action.
managing-task-lifecycle
Use when starting, pausing, completing, or transitioning task status in the development workflow.