When working with multiple branches simultaneously, needing isolated working
directories for parallel development, or managing worktree lifecycle operations.
Worktrees allow multiple working trees attached to the same repository, sharing a
single .git directory. This eliminates stashing, context-switching overhead, and
the risk of uncommitted changes bleeding across tasks.
Use this skill when you need to:
Work on a feature while reviewing another branch
Test different branches simultaneously without cloning
Maintain a clean main checkout while developing in parallel
Set up dmux-style parallel pane workflows with filesystem isolation
Mandatory actions when this skill is active
Before creating worktrees
Understand the model:
A worktree is a separate working directory linked to the same .git store
All worktrees share the same refs, remotes, and object database
Changes committed in any worktree are immediately visible to all others
The "main" worktree is the original clone; "linked" worktrees are additions
Pre-flight checks:
Verify the target branch does not already have a worktree checked out
(git does NOT allow the same branch in two worktrees simultaneously)
Ensure the parent directory for new worktrees exists
Confirm submodule state if the repo uses submodules (they require manual init)
Check available disk space — each worktree is a full working copy
Naming convention (mandatory):
Store worktrees in a sibling .worktrees/ directory:
project/ # main worktree
project/.worktrees/
feat-auth/ # linked worktree for auth feature
fix-payments/ # linked worktree for payments bug
review-pr-42/ # linked worktree for PR review
Name pattern: [type]-[short-description] matching branch suffix
Never nest worktrees inside the main worktree directory
# Continue working on your feature
git worktree add -b feat/new-api ../.worktrees/feat-new-api
# Simultaneously review a colleague's PR
git worktree add ../.worktrees/review-pr-42 origin/feat/their-branch
Test across branches:
git worktree add ../.worktrees/test-main main
git worktree add ../.worktrees/test-release release/2.0
# Run test suites in each directory independently
Integration with dmux-workflows:
One tmux pane per worktree
Each pane cd's into its worktree directory
Each agent instance operates with full filesystem isolation
Merge happens sequentially after all panes complete
Gotchas and constraints:
Cannot checkout the same branch in two worktrees — git enforces this
Submodules are NOT automatically initialized in linked worktrees; run
git submodule update --init in each new worktree if needed
.gitignore'd build artifacts are per-worktree (each has its own node_modules,
build output, etc.)
IDE settings (.vscode/, .idea/) are per-worktree — configure each separately
Hooks in .git/hooks/ are shared across all worktrees
git stash is shared — stashes from one worktree are visible in all
After worktree usage
Cleanup protocol (mandatory after merge):
# Verify the branch is fully merged
git branch --merged main | grep [branch-name]
# Remove the worktree
git worktree remove ../.worktrees/[name]
# Delete the branch if no longer needed
git branch -d [branch-name]
# Prune any stale worktree references
git worktree prune
Never leave stale worktrees:
Stale worktrees consume disk space and pollute git worktree list
After every merge or abandoned branch: remove the corresponding worktree
Run git worktree prune weekly as maintenance hygiene
Use git worktree list to audit — if a worktree's branch no longer exists
on remote, it is likely stale
Post-cleanup verification:
git worktree list shows only the main worktree (or active ones)
No orphaned directories remain in .worktrees/
git branch -v shows no dangling local branches from removed worktrees
Self-check before task completion
Before marking a worktree-related task done:
Did I use the .worktrees/ sibling directory convention?
Did I verify the target branch was not already checked out elsewhere?
Did I handle submodule initialization if applicable?
Did I clean up worktrees after their purpose was fulfilled?
Did I run git worktree prune to remove stale references?
Did I delete merged branches that no longer need worktrees?
Did I verify git worktree list shows a clean state?
1---2name: using-git-worktrees3description: Skill — Using Git Worktrees4---56# Skill — Using Git Worktrees78## When this skill activates910When working with multiple branches simultaneously, needing isolated working11directories for parallel development, or managing worktree lifecycle operations.12Worktrees allow multiple working trees attached to the same repository, sharing a13single `.git` directory. This eliminates stashing, context-switching overhead, and14the risk of uncommitted changes bleeding across tasks.1516Use this skill when you need to:17- Work on a feature while reviewing another branch18- Test different branches simultaneously without cloning19- Maintain a clean main checkout while developing in parallel20- Set up dmux-style parallel pane workflows with filesystem isolation2122## Mandatory actions when this skill is active2324### Before creating worktrees25261. **Understand the model:**27 - A worktree is a separate working directory linked to the same `.git` store28 - All worktrees share the same refs, remotes, and object database29 - Changes committed in any worktree are immediately visible to all others30 - The "main" worktree is the original clone; "linked" worktrees are additions31322. **Pre-flight checks:**33 - Verify the target branch does not already have a worktree checked out34 (git does NOT allow the same branch in two worktrees simultaneously)35 - Ensure the parent directory for new worktrees exists36 - Confirm submodule state if the repo uses submodules (they require manual init)37 - Check available disk space — each worktree is a full working copy38393. **Naming convention (mandatory):**40 - Store worktrees in a sibling `.worktrees/` directory:41 ```42 project/ # main worktree43 project/.worktrees/44 feat-auth/ # linked worktree for auth feature45 fix-payments/ # linked worktree for payments bug46 review-pr-42/ # linked worktree for PR review47 ```48 - Name pattern: `[type]-[short-description]` matching branch suffix49 - Never nest worktrees inside the main worktree directory5051### During worktree usage5253**Core commands:**5455| Operation | Command |56|-----------|---------|57| Create from existing branch | `git worktree add ../.worktrees/[name] [branch]` |58| Create with new branch | `git worktree add -b feat/[name] ../.worktrees/[name]` |59| List all worktrees | `git worktree list` |60| Show worktree details | `git worktree list --verbose` |61| Remove a worktree | `git worktree remove ../.worktrees/[name]` |62| Force remove (dirty) | `git worktree remove --force ../.worktrees/[name]` |63| Clean stale entries | `git worktree prune` |64| Lock (prevent prune) | `git worktree lock ../.worktrees/[name]` |65| Unlock | `git worktree unlock ../.worktrees/[name]` |6667**Workflow patterns:**68691. **Feature + Review parallel:**70 ```bash71 # Continue working on your feature72 git worktree add -b feat/new-api ../.worktrees/feat-new-api73 # Simultaneously review a colleague's PR74 git worktree add ../.worktrees/review-pr-42 origin/feat/their-branch75 ```76772. **Test across branches:**78 ```bash79 git worktree add ../.worktrees/test-main main80 git worktree add ../.worktrees/test-release release/2.081 # Run test suites in each directory independently82 ```83843. **Integration with dmux-workflows:**85 - One tmux pane per worktree86 - Each pane cd's into its worktree directory87 - Each agent instance operates with full filesystem isolation88 - Merge happens sequentially after all panes complete8990**Gotchas and constraints:**91- Cannot checkout the same branch in two worktrees — git enforces this92- Submodules are NOT automatically initialized in linked worktrees; run93 `git submodule update --init` in each new worktree if needed94- `.gitignore`'d build artifacts are per-worktree (each has its own node_modules,95 build output, etc.)96- IDE settings (`.vscode/`, `.idea/`) are per-worktree — configure each separately97- Hooks in `.git/hooks/` are shared across all worktrees98- `git stash` is shared — stashes from one worktree are visible in all99100### After worktree usage1011021. **Cleanup protocol (mandatory after merge):**103 ```bash104 # Verify the branch is fully merged105 git branch --merged main | grep [branch-name]106 # Remove the worktree107 git worktree remove ../.worktrees/[name]108 # Delete the branch if no longer needed109 git branch -d [branch-name]110 # Prune any stale worktree references111 git worktree prune112 ```1131142. **Never leave stale worktrees:**115 - Stale worktrees consume disk space and pollute `git worktree list`116 - After every merge or abandoned branch: remove the corresponding worktree117 - Run `git worktree prune` weekly as maintenance hygiene118 - Use `git worktree list` to audit — if a worktree's branch no longer exists119 on remote, it is likely stale1201213. **Post-cleanup verification:**122 - `git worktree list` shows only the main worktree (or active ones)123 - No orphaned directories remain in `.worktrees/`124 - `git branch -v` shows no dangling local branches from removed worktrees125126## Self-check before task completion127128Before marking a worktree-related task done:129130- [ ] Did I use the `.worktrees/` sibling directory convention?131- [ ] Did I verify the target branch was not already checked out elsewhere?132- [ ] Did I handle submodule initialization if applicable?133- [ ] Did I clean up worktrees after their purpose was fulfilled?134- [ ] Did I run `git worktree prune` to remove stale references?135- [ ] Did I delete merged branches that no longer need worktrees?136- [ ] Did I verify `git worktree list` shows a clean state?
Run npx skillmds@latest add sairam0424/using-git-worktrees in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Skill — Using Git Worktrees It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
sairam0424 (@sairam0424) published this skill. Their other Agent Skills are listed on their SkillMD profile.