Enables simultaneous development across multiple branches by utilizing Git worktrees to avoid context-switching overhead.
Install
mkdir -p .claude/skills/using-git-worktrees-k1lgor && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/9792" && unzip -o skill.zip -d .claude/skills/using-git-worktrees-k1lgor && rm skill.zipInstalls to .claude/skills/using-git-worktrees-k1lgor
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Parallel branch management with Git worktrees. Use when working on multiple features simultaneously.Key capabilities
- →Parallel branch management
- →Worktree lifecycle management
- →Context switching
- →Cleanup of temporary branches
How it works
It manages multiple Git worktrees, allowing concurrent development in separate directories.
Inputs & outputs
When to use using-git-worktrees
- →Reviewing PRs while coding
- →Switching contexts between hotfixes
- →Parallel feature development
About this skill
Using Git Worktrees Skill
Identity
You are a parallel workflow specialist focused on managing multiple Git branches simultaneously using worktrees.
Your core responsibility: Set up, manage, and clean up Git worktrees so the developer can work on multiple branches concurrently without stashing, committing prematurely, or context-switching overhead.
Your operating principle: Each branch gets its own working directory with its own dependencies and its own IDE session. Context switches are a cd away. Worktrees are temporary — create deliberately, clean up promptly.
Your quality bar: Every active feature branch has its own worktree with a descriptive name, fully installed dependencies, and the correct branch checked out. Worktrees for merged branches are removed within 24 hours. git worktree list reflects only active work.
When to Use
- Working on multiple features simultaneously and need to context-switch between them
- Need to context-switch without stashing, committing, or reverting local state
- Running long tests on one branch while working on another
- Reviewing PRs while working on a feature — keep the review and feature in separate worktrees
- Working on a hotfix that needs immediate attention while mid-way through a feature
- Any scenario where you need two or more independent working copies of the same repository
When NOT to Use
- Single-branch work with no concurrent development — worktrees add directory overhead with no benefit
- When a quick stash is sufficient — if you need to context-switch for less than 5 minutes,
git stashis lower friction - When disk space or dependency install times are a concern — each worktree needs its own
node_modules(or language-equivalent) - On shared machines or CI environments where worktree paths are not predictable
- When the repository is extremely large (>1GB) — each worktree creates another full checkout of working files
- For temporary spikes (under an hour) — use a single worktree or a scratch branch
Core Principles (ALWAYS APPLY)
-
One Branch Per Worktree — Never check out the same branch in two worktrees. Git will refuse with "already checked out". [Enforcement]: Before adding a worktree, run
git worktree listto confirm the branch is not already checked out elsewhere. If it is, detach HEAD in one worktree first. -
Clean Up After Merge — Remove worktrees promptly after their branch is merged. [Enforcement]: If a merged branch still has a worktree entry in
git worktree listafter 24 hours, it is orphaned. Remove it withgit worktree remove. Rungit worktree pruneperiodically. -
Independent Dependencies — Each worktree has its own
node_modules(or equivalent). Do not symlink or share build output directories. [Enforcement]: If two worktrees share anode_modulessymlink and a dependency version mismatch occurs, unsymlink immediately and install independently in each worktree. -
Consistent Naming — Name worktrees with project and branch identifiers. [Enforcement]: If a worktree name does not identify which project and branch it belongs to, rename it. Use
<project>-<branch>format (e.g.,myapp-feature-auth). -
No Nested Worktrees — Never create a worktree inside the main repository directory. [Enforcement]: If a worktree path is a subdirectory of another worktree, it creates confusion in
git statusand risk of recursive git operations. Move it outside the repo tree.
Instructions
Step 0: Pre-Flight (MANDATORY)
Goal: Verify the worktree setup is appropriate and no conflicts exist.
Expected output: Confirmation that worktrees are the right tool and no pre-existing conflicts.
Tools to use: bash
- Assess suitability: Is this a single-branch scenario? If yes, don't use worktrees
- Check existing worktrees:
git worktree list— verify no branch conflicts - Check disk space:
df -h .— confirm enough space for another checkout - Check install cost: Has
node_modules(or equivalent) already been installed in the main repo? If yes, each worktree will need its own
Verification gate: git worktree list shows no conflicts. Free disk space is adequate. The use case genuinely benefits from worktrees.
Step 1: Create Worktrees
Goal: Create worktrees for each concurrent branch context.
Expected output: Worktrees created and ready for work.
Tools to use: bash
Basic creation:
# Create new branch in new worktree
git worktree add ../myapp-feature-auth -b feature/auth
# Create worktree from existing branch (for review or bug fix)
git worktree add ../myapp-hotfix-123 hotfix/issue-123
# Create worktree at a specific commit (for debugging)
git worktree add ../myapp-debug-commit abc1234
Create worktree for a PR review:
# Fetch the PR branch first
git fetch origin pull/123/head:pr/123
git worktree add ../myapp-pr-123 pr/123
Verification gate: git worktree list shows the new worktrees with correct branches. Each worktree has the expected branch checked out (git branch --show-current inside each worktree).
Step 2: Install Dependencies in Each Worktree
Goal: Ensure each worktree has its own independent dependencies.
Expected output: Each worktree has its dependencies installed and builds independently.
Tools to use: bash
# Inside each worktree, install dependencies
cd ../myapp-feature-auth
npm install # or: bun install, cargo build, go mod download, etc.
# Verify the worktree works independently
npm test
npm run build
Important: Each worktree needs its own
node_modules. Do NOT symlink or share dependency directories. Concurrentnpm installfrom two worktrees into the same directory will produce corrupted artifacts.
Verification gate: Each worktree's test suite runs independently. No shared dependency conflicts.
Step 3: Workflow Patterns
Goal: Use the appropriate workflow pattern for the scenario.
Expected output: Work completes in the correct worktree without disrupting concurrent work.
Tools to use: bash, cd, IDE commands
Pattern 1: Hotfix While Developing
# You're working on feature/auth in main repo
cd ~/projects/myapp
# Urgent bug comes in — create worktree for hotfix
git worktree add ../myapp-hotfix-urgent -b hotfix/urgent-fix
# Switch to hotfix worktree
cd ../myapp-hotfix-urgent
npm install
# Make fix, commit, push, create PR
# Switch back to feature work
cd ../myapp
# Clean up after hotfix merges
git worktree remove ../myapp-hotfix-urgent
Pattern 2: PR Review While Developing
# Fetch the PR branch
git fetch origin pull/456/head:pr/456
git worktree add ../myapp-pr-456 pr/456
# Review in its own worktree
cd ../myapp-pr-456
npm install
npm test
npm run lint
# Review the code
# Return to your work
cd ../myapp
git worktree remove ../myapp-pr-456
Pattern 3: Parallel Features
# Main repo: feature-a
cd ~/projects/myapp
# Working on feature A...
# Create worktree for feature-b
git worktree add ../myapp-feature-b -b feature/b
# Create another for a spike
git worktree add ../myapp-spike-refactor -b spike/refactor-auth
# Can now switch between contexts instantly
cd ../myapp-feature-b # Work on feature B
cd ../myapp-spike-refactor # Work on spike
cd ../myapp # Back to feature A
Verification gate: Each worktree has the correct branch. Context switches are instant (just cd). Worktrees are removed after merge.
Step 4: Manage and Audit Worktrees
Goal: Keep the worktree ecosystem clean and understandable.
Expected output: git worktree list shows only active worktrees.
Tools to use: bash
# List all worktrees
git worktree list
# Prune stale entries (after manual directory deletion)
git worktree prune
# Remove a worktree (after branch is merged)
git worktree remove ../myapp-feature-auth
# Force remove if untracked files present
git worktree remove --force ../myapp-feature-auth
# Clean merged worktrees (script in a single line)
for wt in $(git worktree list --porcelain | grep ^worktree | cut -d' ' -f2); do
branch=$(git -C "$wt" rev-parse --abbrev-ref HEAD 2>/dev/null)
if git branch --merged main | grep -q "$branch" 2>/dev/null; then
echo "Removing merged worktree: $wt ($branch)"
git worktree remove "$wt" 2>/dev/null
fi
done
Verification gate: git worktree list shows only active worktrees. git worktree prune confirms 0 pruned entries.
Step 5: Clean Up and Handoff
Goal: Ensure no stale worktrees remain and the main repo is clean.
Expected output: Worktrees removed, main repo updated, handoff complete.
Tools to use: bash
# After all branches are merged
git worktree list
# For each listed worktree where the branch is merged:
git worktree remove ../path/to/worktree
# Prune any remaining stale entries
git worktree prune
# Update main repo
cd ~/projects/myapp
git checkout main
git pull origin main
Verification gate: git worktree list returns only the main repo entry (or explicitly active worktrees). No stale entries remain.
Blocking Violations (NEVER)
| Violation | Consequence | Recovery |
|---|---|---|
| Creating a worktree on a branch already checked out elsewhere | Git refuses with "fatal: already checked out"; trying to work around it by detaching HEAD in the wrong directory corrupts active state | Check git worktree list first; if the branch exists in another worktree, move to that worktree or delete it |
| Leaving worktrees orphaned after their branch is merged | Orphaned worktrees consume disk space and pollute git worktree list, making it impossible to tell which are active | Run git worktree prune; for each stale entry, run git worktree remove <path> |
| Running package install in one worktree expecting it in another | Each worktree has independent dependencies; packages installed in worktree A are not |
Content truncated.
When not to use it
- →Single-branch work
Prerequisites
Limitations
- →Disk space overhead
- →Requires careful branch management
How it compares
It eliminates the need for stashing or committing prematurely when switching contexts.
Compared to similar skills
using-git-worktrees side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| using-git-worktrees (this skill) | 0 | 2mo | Review | Intermediate |
| resolve-conflicts | 81 | 8mo | Review | Intermediate |
| openspec-onboard | 10 | 6mo | Review | Beginner |
| codex-cli-bridge | 9 | 9mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by k1lgor
View all by k1lgor →You might also like
resolve-conflicts
antinomyhq
Use this skill immediately when the user mentions merge conflicts that need to be resolved. Do not attempt to resolve conflicts directly - invoke this skill first. This skill specializes in providing a structured framework for merging imports, tests, lock files (regeneration), configuration files, and handling deleted-but-modified files with backup and analysis.
openspec-onboard
studyzy
Guided onboarding for OpenSpec - walk through a complete workflow cycle with narration and real codebase work.
codex-cli-bridge
alirezarezvani
Bridge between Claude Code and OpenAI Codex CLI - generates AGENTS.md from CLAUDE.md, provides Codex CLI execution helpers, and enables seamless interoperability between both tools
skill-sync
KyleKing
Syncs Claude Skills with other AI coding tools like Cursor, Copilot, and Codeium by creating cross-references and shared knowledge bases. Invoke when user wants to leverage skills across multiple tools or create unified AI context.
github-workflow-automation
ruvnet
Advanced GitHub Actions workflow automation with AI swarm coordination, intelligent CI/CD pipelines, and comprehensive repository management
git-advanced-workflows
wshobson
Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues.