Using Git Worktrees

VerifiedSafe

Use git worktrees to work on multiple branches simultaneously. Detects existing worktrees, guards against submodules, and prefers native Claude Code worktree tool over raw git.

Sby Skills Guide Bot
DevelopmentIntermediate
7/22/2026
Claude Code
#git#worktrees#branching#version-control#claude-code

Recommended for

Automated summary

Guides the use of git worktrees to work on several branches at once, preferring Claude Code's native worktree tool over raw git commands.

Strengths

  • Checks for an existing worktree with `git worktree list` before creating a new one
  • Explicitly blocks worktrees in repos with submodules and falls back to `git stash` + `git checkout`
  • Sets a clear priority: native `EnterWorktree`/`ExitWorktree` first, `git worktree add` as fallback
  • Covers cleanup: removal after merge, keeping paused work, and `git worktree prune` for stale references

Limitations

  • Tightly coupled to Claude Code: `EnterWorktree` and `ExitWorktree` do not exist elsewhere
  • Does not address merge conflicts or how to integrate worktree branches back
  • Assumes the user already understands git and the worktree concept
When to use it

Use it when you need to run several branches or tasks in parallel inside one repository without switching directories.

When not to use it

Avoid it in repositories that use submodules, where the author explicitly recommends `git stash` and `git checkout` instead.

Security analysis

Safe
Quality score82/100

The skill only instructs read-only git inspection commands (git worktree list, git submodule status, git worktree prune) and use of native Claude Code worktree tools. There is no destructive deletion of arbitrary paths, no network access, no credential handling, no obfuscation, and no attempt to bypass safety controls. Cleanup is scoped to removing a worktree the agent itself created, which is low risk.

No concerns found

How this analysis is made

Examples

Parallel feature work
I need to start a hotfix while my feature branch is half-finished. Set up a git worktree for the hotfix branch and switch me over, then tell me how to get back.
Check before creating
Before creating anything, check whether a worktree for the branch `feat/auth-refactor` already exists and reuse it if so.
Cleanup after merge
The worktree branch was just merged — exit the worktree, remove it, and prune any stale worktree references.

name: using-git-worktrees description: >- Use git worktrees to work on multiple branches simultaneously. Detects existing worktrees, guards against submodules, and prefers native Claude Code worktree tool over raw git.

Detection

Before creating a worktree, check if one already exists:

git worktree list

If a worktree for the target branch already exists, use it instead of creating a new one.

Guard: Submodules

If the repo uses submodules, DO NOT use git worktrees. Submodules in worktrees are fragile and error-prone. Use git stash + git checkout instead.

To check: git submodule status

Priority: Native Tool First

Prefer EnterWorktree tool over raw git worktree add:

  • EnterWorktree({name: "branch-name"}) — creates worktree and switches session
  • ExitWorktree({action: "keep"|"remove"}) — exits and optionally cleans up

Only use raw git worktree add if the native tool is unavailable or insufficient.

Directory Priority

Worktrees should go in .claude/worktrees/ (Claude Code convention).

When using EnterWorktree, the worktree is automatically placed there.

Cleanup

  • After merging a worktree branch, remove the worktree: ExitWorktree({action: "remove"})
  • If work is paused and you want to keep it: ExitWorktree({action: "keep"})
  • Prune stale worktree references: git worktree prune

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/using-git-worktrees-mrwak9lf/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/using-git-worktrees-mrwak9lf' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/using-git-worktrees-mrwak9lf/download' --output '.skill-downloads/using-git-worktrees-mrwak9lf/SKILL.md.part' && mv '.skill-downloads/using-git-worktrees-mrwak9lf/SKILL.md.part' '.skill-downloads/using-git-worktrees-mrwak9lf/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/using-git-worktrees-mrwak9lf/SKILL.md' && test -s '.skill-downloads/using-git-worktrees-mrwak9lf/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/using-git-worktrees' && cp -R '.skill-downloads/using-git-worktrees-mrwak9lf' '.claude/skills/using-git-worktrees'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/using-git-worktrees-mrwak9lf'

openskills read 'using-git-worktrees-mrwak9lf'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/using-git-worktrees-mrwak9lf/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills