
Using Git Worktrees
- 33 installs
- 36 repo stars
- Updated July 14, 2026
- oimiragieo/agent-studio
Helps with ai & agent building tasks.
About
using-git-worktrees is a Claude Code skill for ai & agent building. It helps solo builders move faster with AI-assisted development.
- using-git-worktrees
- AI & Agent Building
- AI-coding skill
Using Git Worktrees by the numbers
- 33 all-time installs (skills.sh)
- Ranked #8,975 of 16,546 AI & Agent Building skills by installs in the Skillselion catalog
- Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/oimiragieo/agent-studio --skill using-git-worktreesAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 33 |
|---|---|
| repo stars | ★ 36 |
| Last updated | July 14, 2026 |
| Repository | oimiragieo/agent-studio ↗ |
What it does
Helps with ai & agent building tasks.
Files
Using Git Worktrees
Overview
Git worktrees create isolated workspaces sharing the same repository, allowing work on multiple branches simultaneously without switching.
Core principle: Systematic directory selection + safety verification = reliable isolation.
Announce at start: "I'm using the using-git-worktrees skill to set up an isolated workspace."
Directory Selection Process
Follow this priority order:
1. Check Existing Directories
# Check in priority order
ls -d .worktrees 2>/dev/null # Preferred (hidden)
ls -d worktrees 2>/dev/null # AlternativeIf found: Use that directory. If both exist, .worktrees wins.
2. Check CLAUDE.md
grep -i "worktree.*director" CLAUDE.md 2>/dev/nullIf preference specified: Use it without asking.
3. Ask User
If no directory exists and no CLAUDE.md preference:
No worktree directory found. Where should I create worktrees?
1. .worktrees/ (project-local, hidden)
2. ~/.config/claude/worktrees/<project-name>/ (global location)
Which would you prefer?Safety Verification
For Project-Local Directories (.worktrees or worktrees)
MUST verify directory is ignored before creating worktree:
# Check if directory is ignored (respects local, global, and system gitignore)
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/nullIf NOT ignored:
Per standard practice "Fix broken things immediately":
1. Add appropriate line to .gitignore 2. Commit the change 3. Proceed with worktree creation
Why critical: Prevents accidentally committing worktree contents to repository.
For Global Directory (~/.config/claude/worktrees)
No .gitignore verification needed - outside project entirely.
Creation Steps
1. Detect Project Name
project=$(basename "$(git rev-parse --show-toplevel)")2. Create Worktree
# Determine full path
case $LOCATION in
.worktrees|worktrees)
path="$LOCATION/$BRANCH_NAME"
;;
~/.config/claude/worktrees/*)
path="~/.config/claude/worktrees/$project/$BRANCH_NAME"
;;
esac
# Create worktree with new branch
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"3. Run Project Setup
Auto-detect and run appropriate setup:
# Node.js
if [ -f package.json ]; then npm install; fi
# Rust
if [ -f Cargo.toml ]; then cargo build; fi
# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi
# Go
if [ -f go.mod ]; then go mod download; fi4. Verify Clean Baseline
Run tests to ensure worktree starts clean:
# Examples - use project-appropriate command
npm test
cargo test
pytest
go test ./...If tests fail: Report failures, ask whether to proceed or investigate.
If tests pass: Report ready.
5. Report Location
Worktree ready at <full-path>
Tests passing (<N> tests, 0 failures)
Ready to implement <feature-name>Quick Reference
| Situation | Action |
|---|---|
.worktrees/ exists | Use it (verify ignored) |
worktrees/ exists | Use it (verify ignored) |
| Both exist | Use .worktrees/ |
| Neither exists | Check CLAUDE.md -> Ask user |
| Directory not ignored | Add to .gitignore + commit |
| Tests fail during baseline | Report failures + ask |
| No package.json/Cargo.toml | Skip dependency install |
Common Mistakes
Skipping ignore verification
- Problem: Worktree contents get tracked, pollute git status
- Fix: Always use
git check-ignorebefore creating project-local worktree
Assuming directory location
- Problem: Creates inconsistency, violates project conventions
- Fix: Follow priority: existing > CLAUDE.md > ask
Proceeding with failing tests
- Problem: Can't distinguish new bugs from pre-existing issues
- Fix: Report failures, get explicit permission to proceed
Hardcoding setup commands
- Problem: Breaks on projects using different tools
- Fix: Auto-detect from project files (package.json, etc.)
Example Workflow
You: I'm using the using-git-worktrees skill to set up an isolated workspace.
[Check .worktrees/ - exists]
[Verify ignored - git check-ignore confirms .worktrees/ is ignored]
[Create worktree: git worktree add .worktrees/auth -b feature/auth]
[Run npm install]
[Run npm test - 47 passing]
Worktree ready at /Users/dev/myproject/.worktrees/auth
Tests passing (47 tests, 0 failures)
Ready to implement auth featureRed Flags
Never:
- Create worktree without verifying it's ignored (project-local)
- Skip baseline test verification
- Proceed with failing tests without asking
- Assume directory location when ambiguous
- Skip CLAUDE.md check
Always:
- Follow directory priority: existing > CLAUDE.md > ask
- Verify directory is ignored for project-local
- Auto-detect and run project setup
- Verify clean test baseline
Integration
Called by:
- brainstorming (Phase 4) - REQUIRED when design is approved and implementation follows
- Any skill needing isolated workspace
Pairs with:
- finishing-a-development-branch - REQUIRED for cleanup after work complete
- executing-plans or subagent-driven-development - Work happens in this worktree
Iron Laws
1. ALWAYS verify .gitignore includes the worktree directory pattern before creating any worktree 2. NEVER create a worktree on a dirty working tree — stash or commit changes first 3. ALWAYS use project-local directories inside the project for worktree placement 4. NEVER delete a worktree with uncommitted changes without explicit user confirmation 5. ALWAYS run git worktree prune after removing worktrees to clean up stale metadata
Anti-Patterns
| Anti-Pattern | Why It Fails | Correct Approach |
|---|---|---|
| Creating worktree with dirty working tree | Uncommitted changes risk loss or confusion | Stash or commit changes before creating worktree |
| Worktree outside project directory | Not covered by .gitignore, leaks to VCS | Use project-local paths inside the repo |
| No .gitignore entry for worktree directory | Worktree files pollute git status output | Add worktree path pattern to .gitignore first |
| Deleting worktree without checking changes | Uncommitted work silently lost | Check for uncommitted changes before removal |
Forgetting git worktree prune | Stale lock files block future worktree creation | Always prune after removing worktrees |
Memory Protocol (MANDATORY)
Before starting: Read .claude/context/memory/learnings.md
After completing:
- New pattern ->
.claude/context/memory/learnings.md - Issue found ->
.claude/context/memory/issues.md - Decision made ->
.claude/context/memory/decisions.md
ASSUME INTERRUPTION: If it's not in memory, it didn't happen.
Invoke the using-git-worktrees skill and follow it exactly as presented to you
'use strict';
/**
* Post-execute hook for using-git-worktrees
* Auto-generated by enterprise-bundle-scaffolder
*
* Records metrics after skill execution.
*/
function postExecute(_context) {
// Record execution metrics
return { ok: true, skill: 'using-git-worktrees' };
}
module.exports = { postExecute };
'use strict';
/**
* Pre-execute hook for using-git-worktrees
* Auto-generated by enterprise-bundle-scaffolder
*
* Validates inputs before skill execution.
*/
function preExecute(context) {
// Validate skill invocation context
if (!context || typeof context !== 'object') {
return { allow: true, message: 'using-git-worktrees: no context to validate' };
}
return { allow: true };
}
module.exports = { preExecute };
using-git-worktrees Research Requirements
Generated: 2026-02-28
Skill Description
Create isolated development workspaces with safety verification. Use when needing parallel development branches.
Research Areas
- Current best practices for using-git-worktrees
- Industry standards and tooling
- Integration patterns
Source References
- To be populated by skill-updater research phase
using-git-worktrees Rules
Purpose
Create isolated development workspaces with safety verification. Use when needing parallel development branches.
Best Practices
- Verify .gitignore includes worktree directories
- Clean baseline before creating worktree
- Use project-local directories when possible
Integration Points
See SKILL.md for complete documentation.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "using-git-worktrees Input Schema",
"description": "Input validation schema for using-git-worktrees skill",
"type": "object",
"required": [],
"properties": {},
"additionalProperties": true
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "using-git-worktrees Output Schema",
"description": "Output validation schema for using-git-worktrees skill",
"type": "object",
"required": ["success"],
"properties": {
"success": {
"type": "boolean",
"description": "Whether the skill executed successfully"
},
"result": {
"type": "object",
"description": "The skill execution result",
"additionalProperties": true
},
"error": {
"type": "string",
"description": "Error message if execution failed"
}
},
"additionalProperties": true
}
#!/usr/bin/env node
/**
* Using Git Worktrees - Main Script
* Create isolated development workspaces with safety verification — sets up git worktrees for parallel feature work without affecting main working tree
*/
const options = Object.fromEntries(
process.argv
.slice(2)
.filter(arg => arg.startsWith('--'))
.map(flag => [flag.replace(/^--/, ''), true])
);
if (options.help) {
console.log('Using Git Worktrees - Main Script');
process.exit(0);
}
console.warn('WARNING: This skill is currently a scaffold and has no implementation.');
process.exit(1);
using-git-worktrees Implementation Template
Goal
- Define target outcome and acceptance criteria.
TDD
1. Red 2. Green 3. Refactor
Verification
- lint
- format
- targeted tests