From dev-workflow-skills
Use when starting feature work that needs isolation, before executing implementation plans, or whenever the user mentions branching, parallel work, or wanting a clean workspace. Creates isolated git worktrees with systematic directory selection and safety verification. Use this skill even if the user just says "let's work on this in a branch" or "set up a workspace for this."
How this skill is triggered — by the user, by Claude, or both
Slash command
/dev-workflow-skills:using-git-worktreesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Git worktrees let you work on multiple branches simultaneously — each worktree is an independent checkout sharing the same `.git` directory. Agents can operate in isolated worktrees without disrupting the user's main workspace.
Git worktrees let you work on multiple branches simultaneously — each worktree is an independent checkout sharing the same .git directory. Agents can operate in isolated worktrees without disrupting the user's main workspace.
Announce at start: "I'm using the using-git-worktrees skill to set up an isolated workspace."
Before creating anything:
Present the worktree details like:
Git worktree:
Parent branch: main
New branch: feature/<descriptive-name>
Directory: .worktrees/feature/<descriptive-name>
Once the worktree is created, do all work inside the worktree directory — not in the main worktree.
.worktrees/ is Gitignoredgit check-ignore -q .worktrees/ 2>/dev/null
If NOT ignored, add .worktrees/ to .gitignore and commit before proceeding.
git worktree add .worktrees/<branch-name> -b <branch-name>
cd .worktrees/<branch-name>
If the branch already exists, either reuse it (git worktree add .worktrees/<name> <existing-branch>) or pick a different name. If the worktree directory already exists, ask the user whether to reuse or remove it.
Run the repo's dependency install command. Check Makefile, README, or project instructions (copilot-instructions.md, CLAUDE.md) for the standard install step. Common patterns:
make installuv sync --all-extrasnpm installEach worktree gets its own dependency environment for isolation.
Check project docs for repo-specific setup steps beyond dependency installation. Common examples:
git submodule update --init --recursive.env or credentials that need copyingApply all repo-specific steps before running baseline verification.
Verify that symlinks or generated files created during setup are gitignored. This prevents git add -A from accidentally staging them.
git check-ignore -q <symlink-or-generated-path> 2>/dev/null || echo "WARNING: not ignored"
If not ignored, use selective git add <files> instead of git add -A during commits.
Run the project's validation command (check Makefile or project docs):
make all # or whatever the project uses
Worktree ready at <full-path>
Branch: <branch-name> (from <parent-branch>)
Validation passing
Ready to work on <task-description>
When work in a worktree is complete, follow these steps in order.
cd .worktrees/<branch-name>
git add -u && git commit -m "<message>"
Use git add -u (stages only tracked files). Never use git add -A or git add . in worktrees — they can stage symlinks or generated files created during post-checkout setup.
Optionally push to remote if collaboration or backup is needed:
git push -u origin <branch-name>
Before merging, verify the branch doesn't track paths created during post-checkout setup (symlinks, generated files). Check project docs for the list of repo-specific paths.
git ls-tree -r --name-only <branch-name> | grep -q '^<path>$' && echo "DANGER" || echo "OK"
If a repo-specific path is tracked, remove it before merging:
git rm --cached <path>
git commit -m "fix: remove accidentally tracked <path>"
Switch to the main worktree root (not the feature worktree) and merge:
cd <main-worktree-root>
git checkout <parent-branch>
git merge <branch-name>
If merge conflicts arise, follow the project's conflict resolution guidelines. General approach:
Remove the worktree before deleting the branch. If the worktree has submodules, deinit them first:
# With submodules:
cd .worktrees/<branch-name>
git submodule deinit -f --all
cd <main-worktree-root>
git worktree remove --force .worktrees/<branch-name>
# Without submodules:
git worktree remove .worktrees/<branch-name>
git branch -d <branch-name>
If the branch was pushed to remote:
git push origin --delete <branch-name>
| Situation | Action |
|---|---|
.worktrees/ not ignored | Add to .gitignore and commit |
| Branch already exists | Reuse it or pick a different name |
| Worktree directory already exists | Ask user whether to reuse or remove |
| Tests fail during baseline | Report failures and ask user |
| Merge conflicts on cleanup | Follow project conflict resolution guidelines |
| Worktree has submodules | git submodule deinit -f --all then git worktree remove --force |
| Repo-specific symlinks not gitignored | Use git add -u instead of git add -A |
| Branch tracks repo-specific paths | Remove with git rm --cached <path> before merging |
git add -A stages symlinks or generated files created during post-checkout setup. Merging these can overwrite real directories with symlinks.git add -u. Never use git add -A or git add . in worktrees.git ls-tree -r --name-only <branch> | grep '<path>') before every merge..worktrees/ directory get tracked, polluting git status.git check-ignore on .worktrees/ and on any paths created during setup.git worktree remove errors because git submodule deinit leaves metadata that git considers "dirty."git worktree remove --force after submodule deinit.Never:
.worktrees/ is gitignoredgit add -A or git add . in worktreesAlways:
.worktrees/ is in .gitignoregit add -u for stagingGuides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub tt6746690/skills --plugin wpq-skills