Automates creation and management of headless git worktree structures.
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.
Invoke this skill when users request:
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:
.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"
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:
.bare/ directoryThe conversion is done in-place, preserving remote configuration
Example request: "Convert my existing project to use 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:
Example request: "Add a worktree for the feature/auth branch"
For operations not covered by scripts, use git worktree commands directly:
List all worktrees:
git worktree list
Remove a worktree:
git worktree remove branch-name
# Optionally delete the branch
git branch -d branch-name
Prune stale worktrees:
git worktree prune
Move a worktree:
git worktree move old-path new-path
For detailed explanation of worktree patterns, benefits, and best practices, reference references/worktree_patterns.md. Load this reference when:
Key benefits:
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 needed
Submodules not initialized: Each worktree needs its own submodule initialization:
cd worktree-directory
git submodule update --init --recursive
When implementing worktree setups:
.bare/ already exists before convertingcd into the worktree directory to start workingmain branch, but allow override for repos using master or other default branchessetup_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 intelligentlyworktree_patterns.md - Comprehensive guide to worktree patterns, benefits, gotchas, and best practices