git-worktree-setup
Skill0 starsChanged 13 months agoMITView on GitHub
Automates creation and management of headless git worktree structures. Use when the user requests to clone a repository with worktree setup, convert an existing repository to use worktrees, or add new worktrees to a bare repository. Triggers on requests like "set up worktrees", "headless git setup", "bare repo with worktrees", or "add a worktree for branch X".
3 other projects use a version of this.
Adopted by
Most recently taken up by
- eliasjnior/claude-skillstheir own version, first seen Nov 1, 2026
- gigio1023/agent-skillstheir own version, first seen Oct 13, 2026
- gigio1023/gigio-skillstheir own version, first seen Oct 13, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- gigio1023/agent-skills★ 2same name
- gigio1023/gigio-skills★ 2same name
- eliasjnior/claude-skills★ 0same name
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 repositoryOne other file it gives its agents.
- flashcardsSkill
The file
We split this skill into the rules it gives an agent
11 rules. 0 are common, 9 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
9
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
When the user provides a GitHub URL and wants worktree structure:
- Distinctive: line 34
Create the default branch worktree
- Distinctive: line 49
When the user has an existing cloned repository to convert:
- Distinctive: line 58
Create a bare repository from the existing repo
- Distinctive: line 60
Create worktree for the default branch
- Distinctive: line 69
When adding branches to an existing worktree-structured repository:
- Distinctive: line 129
No need to stash changes when switching branches
- Very specific: line 142
Ensure running from the root directory containing .bare/ and .git file (not .git directory).
- Distinctive: line 159
When implementing worktree setups:
- Very specific: line 160
Always check if .bare/ already exists before converting
- Distinctive: line 165
Default to main branch, but allow override for repos using master or other default branches
“Common” is measured: kept by at least 6 in 10 of the 3 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 Setup
Overview
Automate the creation and management of git repositories using a bare repository with worktrees structure. This approach allows working on multiple branches simultaneously without switching contexts, stashing changes, or reinstalling dependencies.
When to Use This Skill
Invoke this skill when users request:
- Setting up a new repository from GitHub with worktree structure
- Converting an existing cloned repository to use worktrees
- Adding new worktrees to an existing bare repository setup
- Explaining or troubleshooting worktree configurations
Core Workflows
1. Clone and Setup from GitHub
When the user provides a GitHub URL and wants worktree structure:
- Use
scripts/setup_bare_repo.sh:bash setup_bare_repo.sh <github-url> <target-dir> [default-branch] - The script will:
- Clone the repository as bare (
.bare/) - Configure remote tracking
- Create the default branch worktree
- Set up the directory structure
- Clone the repository as bare (
- Result structure:
target-dir/ ├── .bare/ # Bare repository ├── .git # Pointer to .bare └── main/ # Default branch worktree
Example request: "Clone my-org/my-repo and set it up with worktrees"
2. Convert Existing Repository
When the user has an existing cloned repository to convert:
- Use
scripts/convert_to_worktree.sh:bash convert_to_worktree.sh <repo-path> [default-branch] - The script will:
- Warn about uncommitted changes (user must confirm)
- Create a bare repository from the existing repo
- Restructure to use
.bare/directory - Create worktree for the default branch
- Clean up the old working directory
- The conversion is done in-place, preserving remote configuration
Example request: "Convert my existing project to use worktrees"
3. Add New Worktrees
When adding branches to an existing worktree-structured repository:
- Navigate to the repository root (where
.bare/exists) - Use
scripts/add_worktree.sh:# Create new branch from base bash add_worktree.sh feature/new-api main # Checkout existing remote branch bash add_worktree.sh bugfix/urgent # Create new branch from HEAD bash add_worktree.sh experimental - The script intelligently:
- Checks if branch exists locally or remotely
- Creates new branch if needed
- Sets up tracking appropriately
- Creates worktree directory with branch name
Example request: "Add a worktree for the feature/auth branch"
Manual Worktree Operations
For operations not covered by scripts, use git worktree commands directly:
List all worktrees:
git worktree listRemove a worktree:
git worktree remove branch-name
# Optionally delete the branch
git branch -d branch-namePrune stale worktrees:
git worktree pruneMove a worktree:
git worktree move old-path new-pathUnderstanding Worktree Benefits
For detailed explanation of worktree patterns, benefits, and best practices, reference references/worktree_patterns.md. Load this reference when:
- User asks "why use worktrees?"
- User wants to understand the trade-offs
- Troubleshooting issues
- Explaining the directory structure
Key benefits:
- Work on multiple branches simultaneously
- No need to stash changes when switching branches
- Clean isolation (separate node_modules, build artifacts per branch)
- Better IDE integration (separate language server instances)
- Simplified local testing of multiple branches
Common Troubleshooting
Script not executable:
chmod +x scripts/*.sh"Not in a bare repository setup" error:
Ensure running from the root directory containing .bare/ and .git file (not .git directory).
Worktree already exists:
git worktree list # Check existing worktrees
git worktree remove old-worktree # Remove if neededSubmodules not initialized: Each worktree needs its own submodule initialization:
cd worktree-directory
git submodule update --init --recursiveImplementation Notes
When implementing worktree setups:
- Always check if
.bare/already exists before converting - Make scripts executable after writing them
- Provide clear feedback about directory structure after setup
- Remind users to
cdinto the worktree directory to start working - Handle both SSH and HTTPS GitHub URLs
- Default to
mainbranch, but allow override for repos usingmasteror other default branches
Resources
scripts/
setup_bare_repo.sh- Clone from GitHub and create bare + worktree structureconvert_to_worktree.sh- Convert existing repository to worktree structureadd_worktree.sh- Add new worktrees intelligently
references/
worktree_patterns.md- Comprehensive guide to worktree patterns, benefits, gotchas, and best practices
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.

