using-git-worktrees
Safely creates task-specific workspaces before commencing any code modification.
Install
mkdir -p .claude/skills/using-git-worktrees-leohara && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/12843" && unzip -o skill.zip -d .claude/skills/using-git-worktrees-leohara && rm skill.zipInstalls to .claude/skills/using-git-worktrees-leohara
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Create a task-specific git worktree under `.worktrees/` at the repository root before making code changes. Treat the primary workspace as investigation-only, create each new worktree from the default base branch using `<type>/<short-kebab-slug>`, and hand off final verification to `code-change-verification`.Key capabilities
- →Create task-specific git worktrees
- →Ensure worktrees are created under `.worktrees/` at repository root
- →Update `.gitignore` if `.worktrees/` is not ignored
- →Determine the correct base branch for new worktrees
- →Perform baseline verification after worktree setup
- →Hand off to `code-change-verification` for final checks
How it works
The skill creates a git worktree from a determined base branch, ensures the worktree directory is ignored, performs necessary setup, and runs baseline verification tests.
Inputs & outputs
When to use using-git-worktrees
- →Create task workspace
- →Prepare for refactoring
- →Start implementation work
About this skill
Using Git Worktrees
When To Apply
- Use this when you may touch files under Git control, such as implementation, refactoring, configuration changes, documentation updates, or edits under
.codex/ - Use this before
code-change-verificationwhen the task should run in its own isolated checkout - If you are already in the correct task worktree, continue there
Required Rules
- At the start, explicitly say
I'm using the using-git-worktrees skill to set up an isolated workspace. - Use the primary workspace only for light investigation and adjustments. Do not perform editing work there.
- Always create a new task worktree from the default base branch. Do not use the currently checked out feature branch or a temporary branch as the base.
- For the base branch, prefer any explicit workflow rule defined by the repository. If none exists, determine it in this order:
origin/HEAD,main,develop,master. If it still cannot be determined, specify it explicitly before continuing. - Create worktrees under
.worktrees/at the repository root. - If
.worktrees/is not ignored, update.gitignorebefore continuing. - If the repository has a wrapper command for worktree creation, use it first. Otherwise use this skill's
scripts/worktree-add.sh. - If this repository also uses
code-change-verification, treat this skill as the setup phase andcode-change-verificationas the final verification gate for runtime, test, build, or UI-related changes. - Baseline verification in this skill only proves the new worktree is usable. It does not replace the final verification pass after implementation.
- If worktree creation, removal, or branch operations fail because of permissions, request escalation immediately and continue the process.
Relationship To code-change-verification
- This skill prepares the isolated checkout that downstream work should use.
- The expected handoff to
code-change-verificationis: worktree path, base branch, setup status, baseline verification results, and any environment blockers discovered during setup. - After code changes exist in the task worktree, run
code-change-verificationthere instead of returning to the primary workspace.
Steps
1. Check Your Current Location
pwd
git branch --show-current
git worktree list
git status --short
2. Check That .worktrees/ Exists And Is Ignored
# Run this from the repository root
mkdir -p .worktrees
git check-ignore -v .worktrees
3. Decide The Base Branch And Task Branch Name
- Check the repository workflow for the base branch. If no rule exists, determine it in this order:
origin/HEAD,main,develop,master - Use the format
<type>/<short-kebab-slug> - Valid
typevalues arefeature,fix,refactor,chore,docs,test - Create the worktree directory name by replacing
/in the branch name with-
4. Create The Worktree From The Base Branch
BASE_BRANCH=main
BRANCH_NAME=feature/example-task
WORKTREE_NAME="${BRANCH_NAME//\//-}"
# Prefer the repository's wrapper command if one exists
# Example: pnpm worktree:add -- --base "$BASE_BRANCH" "$BRANCH_NAME"
# Run this from the repository root
sh .codex/skills/using-git-worktrees/scripts/worktree-add.sh --base "$BASE_BRANCH" "$BRANCH_NAME"
cd ".worktrees/$WORKTREE_NAME"
5. Set Up The Worktree
- Run only the setup that is required, following the repository's standard procedure
- Examples:
pnpm install,npm install,bun install,cargo fetch - If it fails because of network restrictions, request escalation and rerun it
6. Baseline Verification
- Run one or more standard non-mutating checks for that repository
- Examples:
pnpm lint,pnpm test,pnpm typecheck,cargo test,go test ./... - Do not use mutating or long-running commands such as
format,db:migrate,seed, ordevas baseline checks - If a check fails because required environment variables or credentials are missing, state exactly which prerequisite is missing and decide whether to continue
- If you cannot find any executable baseline check, report that fact before proceeding
- If the task will continue into runtime, test, build, or UI changes, plan to rerun the final verification stack later with
code-change-verificationfrom this worktree
7. Report That The Setup Is Ready
Worktree ready at <full-path>
Based on <base-branch>: <commit>
Verification: <commands or skipped with reason>
Final verification: run `code-change-verification` from this worktree before claiming completion
Ready to implement <task>
8. Hand Off To code-change-verification
- Keep implementation and final verification inside the same task worktree whenever possible.
- Use the baseline verification output from this skill only as setup evidence.
- Once the diff exists, invoke
code-change-verificationfrom the task worktree and report fresh results from that pass.
If You Used The Wrong Base Branch
Confirm that the worktree is clean, then remove it and recreate it from the correct base branch with a fresh branch name. If you need to reuse the old branch name, handle that branch cleanup separately and explicitly.
For Codex command execution, do not use git -C .... Set workdir to the target worktree and run plain git commands so the repository rules apply cleanly.
BASE_BRANCH=main
OLD_BRANCH_NAME=feature/example-task
OLD_WORKTREE_NAME="${OLD_BRANCH_NAME//\//-}"
NEW_BRANCH_NAME=feature/example-task-v2
# Run this with workdir set to ".worktrees/$OLD_WORKTREE_NAME"
git status --short
git worktree remove ".worktrees/$OLD_WORKTREE_NAME"
# Run this from the repository root
sh .codex/skills/using-git-worktrees/scripts/worktree-add.sh --base "$BASE_BRANCH" "$NEW_BRANCH_NAME"
What Not To Do
- Create a task worktree from the currently checked out feature branch
- Edit directly in the primary workspace
- Skip checking whether
.worktrees/is ignored - Silently ignore a baseline failure
- Treat baseline verification as a replacement for
code-change-verification
When not to use it
- →When making changes that do not involve files under Git control
- →When the user needs to edit directly in the primary workspace
Limitations
- →The skill's scope is limited to worktree creation and initial setup
- →The skill does not replace final verification after implementation
How it compares
This skill enforces a structured workflow for isolated code changes, integrating safety checks and a clear handoff to a verification process, which is more reliable than ad-hoc worktree usage.
Compared to similar skills
using-git-worktrees side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| using-git-worktrees (this skill) | 0 | 4mo | Review | Intermediate |
| resolve-conflicts | 81 | 8mo | Review | Intermediate |
| openspec-onboard | 10 | 6mo | Review | Beginner |
| codex-cli-bridge | 9 | 9mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
resolve-conflicts
antinomyhq
Use this skill immediately when the user mentions merge conflicts that need to be resolved. Do not attempt to resolve conflicts directly - invoke this skill first. This skill specializes in providing a structured framework for merging imports, tests, lock files (regeneration), configuration files, and handling deleted-but-modified files with backup and analysis.
openspec-onboard
studyzy
Guided onboarding for OpenSpec - walk through a complete workflow cycle with narration and real codebase work.
codex-cli-bridge
alirezarezvani
Bridge between Claude Code and OpenAI Codex CLI - generates AGENTS.md from CLAUDE.md, provides Codex CLI execution helpers, and enables seamless interoperability between both tools
skill-sync
KyleKing
Syncs Claude Skills with other AI coding tools like Cursor, Copilot, and Codeium by creating cross-references and shared knowledge bases. Invoke when user wants to leverage skills across multiple tools or create unified AI context.
github-workflow-automation
ruvnet
Advanced GitHub Actions workflow automation with AI swarm coordination, intelligent CI/CD pipelines, and comprehensive repository management
git-advanced-workflows
wshobson
Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues.