git-worktree
Skill1 starsChanged 5 months agoMITView on GitHub
Git worktree management for AI Agents — create, use, and clean up isolated working trees. Use when an agent needs to work on multiple branches simultaneously without cloning.
- Deletes or force-pushes
30 other projects use a version of this.
Adopted by
Most recently taken up by
- aegntic/compound-engineeringtheir own version, first seen Nov 8, 2026
- sbluemin/fleet-harnesstheir own version, first seen Nov 8, 2026
- yht-4403/jc-agent-skillstheir own version, first seen Nov 8, 2026
- yuri-xyz/skillstheir own version, first seen Nov 8, 2026
- iliaal/ai-skillstheir own version, first seen Nov 7, 2026
- eliasjnior/claude-skillstheir own version, first seen Nov 1, 2026
Used with
Projects with it also use agent-native-architecture, document-review and 7 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
CodeWithBehnamSkillagent-native-architecture
Build applications where agents are first-class citizens. Use this skill when designing autonomous agents, creating MCP tools, implementing self-modifying systems, or building apps where features are outcomes achieved by agents operating in a loop.
Also in 3 projects that use this
CodeWithBehnamSkilldocument-review
This skill should be used to refine brainstorm or plan documents before proceeding to the next workflow step. It applies when a brainstorm or plan document exists and the user wants to improve it.
Also in 3 projects that use this
MicrosoftSkillgit-commit
Stage user-selected paths, confirm the exact staged set, and create one local Conventional Commit, or generate a commit message for staged changes without committing. Use when you want a guarded commit or a ready-to-paste message.
Also in 3 projects that use this
MicrosoftSkillgrill-with-docs
Grilling session that challenges your plan against the existing domain model, sharpens terminology, and updates documentation (CONTEXT.md, ADRs) inline as decisions crystallise. Use when user wants to stress-test a plan against their project's language and documented decisions.
Also in 3 projects that use this
OpenAISkillbrainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.
Also in 3 projects that use this
BlockSkillfrontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Also in 4 projects that use this
Other versions30 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 30
- davidondrej/skills★ 4.3ksame name
- iliaal/ai-skills★ 45same name
- sbluemin/fleet-harness★ 17same name
- BackToCimaCoppi/Praxis★ 6same name
- dzianisv/skills★ 4same name
- KroxiDev/engineering-skills★ 4same name
- MithunWijayasiri/dotclaude★ 4same name
- CodeWithBehnam/cc-docs★ 2same name
- hmj1026/dhpk★ 2same name
- tsubakimoto/skills★ 2same name
20 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository8 other files it gives its agents.
- ai-cognitive-loadSkill
- android-controlSkill
- autonomous-researchSkill
- cron-task-specSkill
- hermes-pr-guidelinesSkill
- jj-workspaceSkill
- knowledge-explorerSkill
- xurl-best-practicesSkill
The file
We split this skill into the rules it gives an agent
3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 25 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 139
Solution: Always use git worktree remove.
- Very specific: line 143
Solution: Test the no-remote scenario separately.
- Distinctive: line 147
Solution: Use absolute paths or anchor via git worktree list --porcelain to obtain the path.
“Common” is measured: kept by at least 6 in 10 of the 25 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Worktree — Agent Workspace Isolation
Agents use git worktree to safely work in parallel across multiple branches. Covers the full lifecycle of creation, switching, and cleanup, as well as concurrency safety pitfalls.
Triggers
- Agent needs to work on multiple branches simultaneously in the same repository
- Agent needs an isolated workspace to avoid polluting the main working directory
- Kanban / pipeline requires per-task independent checkouts
- User mentions "git worktree", "parallel development", "multi-branch simultaneous work"
Requirements
- Git >= 2.35 (recommended) — 2.5+ usable, 2.35+ includes fetch protection for all worktree branches
- Verify:
git --version
Lifecycle
1. Create Worktree
# Standard creation (auto-creates branch with same name)
git worktree add <path> -b <branch-name>
# Agent recommended pattern: internal directory + task ID naming
WORKTREE_DIR=".worktrees/$(date +%s)-${TASK_ID}"
git worktree add "$WORKTREE_DIR" -b "wt/${TASK_ID}"
# Create from existing branch
git worktree add <path> <existing-branch>
# Detached HEAD (temporary work)
git worktree add -d <path>2. Use Worktree
cd <worktree-path>
# Normal development...
git status
git add ...
git commit ...3. List & Status
git worktree list # Human-readable
git worktree list --porcelain # Script parsing
git worktree list --verbose # Includes prune information4. Lock Protection
# Lock an active worktree (prevents automatic pruning)
git worktree lock <path> --reason "active agent task TASK-123"
# Unlock
git worktree unlock <path>5. Cleanup
# Standard cleanup (requires clean working tree + no unpushed commits)
git worktree remove <path>
# Force cleanup
git worktree remove --force <path>
# Clean up metadata (must run after manual rm -rf of directory)
git worktree prune
# Clean by expiration age
git worktree prune --expire 7.days.agoRecommended Patterns for Agents
Per-Task Worktree (Kanban / Pipeline)
# Create
TASK_ID="t_8894c1db"
WORKTREE=".worktrees/${TASK_ID}"
git worktree add "$WORKTREE" -b "wt/${TASK_ID}"
# Clean up after task completion
git worktree remove "$WORKTREE" 2>/dev/null || {
# Dirty worktree protection: lock + preserve
git worktree lock "$WORKTREE" --reason "dirty: ${TASK_ID}"
echo "WARNING: worktree $WORKTREE preserved (dirty)"
}
git worktree pruneMulti-Agent Parallel Pattern
# Agent 1
git worktree add .worktrees/agent-1 -b wt/agent-1
# Agent 2
git worktree add .worktrees/agent-2 -b wt/agent-2
# Each agent works independently in its own worktree
# Note: branch names must be unique (guaranteed by naming convention)Concurrency Safety Rules
| Rule | Description |
| Unique branch names | Each worktree must be bound to a different branch (or detached HEAD) |
| Protect with lock | Lock active worktrees; git worktree prune skips locked entries |
| Prefer remove over rm -rf | git worktree remove cleans metadata; after manual rm -rf, run git worktree prune |
| Internal directory | Use .worktrees/ instead of external paths for unified management |
Pitfalls
1. Branch Name Conflict
fatal: 'wt/task-123' is already checked out by '.worktrees/task-123'Cause: Multiple agents attempt to create a worktree with the same name from the same working directory. Solution: Include a unique ID (timestamp / task ID) in the branch name.
2. Manual rm -rf Leaves Stale Metadata
Symptom: git worktree list still shows the deleted worktree (marked as prunable).
Solution: Always use git worktree remove; if already manually deleted, run git worktree prune.
3. No Remote Repository Scenario
Symptom: git worktree remove behaves differently in local repositories (never pushed).
Solution: Test the no-remote scenario separately; --force may be required.
4. Relative Path Resolution
Symptom: Agent frameworks may resolve file operations to the process cwd rather than the worktree path.
Solution: Use absolute paths or anchor via git worktree list --porcelain to obtain the path.
5. Stale Worktree Accumulation
Symptom: Abandoned worktrees consume disk space (100 MB–2 GB+ each). Solution: Implement a cleanup policy — skip if < 24h, delete if 24h–72h with no push, force delete if 72h+.
Configuration Recommendations
# Auto-cleanup configuration
git config gc.worktreePruneExpire 7.days.ago
# Agent environments can be more aggressive
git config gc.worktreePruneExpire 3.days.agoQuick Reference
| Operation | Command |
| Create | git worktree add <path> -b <branch> |
| List | git worktree list |
| Lock | git worktree lock <path> --reason "..." |
| Unlock | git worktree unlock <path> |
| Remove | git worktree remove <path> |
| Prune | git worktree prune |
| Move | git worktree move <old> <new> |
| Repair | git worktree repair [<path>...] |
Sources
- Git official documentation:
git worktree --help - Hermes Agent worktree implementation (2026.03+)
- Claude Code worktree documentation: https://code.claude.com/docs/en/worktrees
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

