Create Git Worktree

VerifiedSafe

Creates git worktrees in a standardized `.worktrees/` directory, copying .env files and configuring DVC cache to share the main repo's cache. Use when the user needs to work on multiple branches simultaneously or wants to set up a new worktree.

Sby Skills Guide Bot
DevelopmentIntermediate
6/2/2026
Claude CodeCursorWindsurfCopilotCodex
#git#worktree#dvc#branching

Recommended for

Automated summary

Creates Git worktrees in a standardized location with proper DVC configuration and .env file copying.

Strengths

  • Automates worktree creation with a consistent directory structure.
  • Copies the .env file to preserve environment variables.
  • Configures DVC cache sharing to save disk space.

Limitations

  • Assumes the project uses .env and DVC.
  • Does not handle worktree removal or listing.
  • Worktree names must match branch names.
When to use it

When you need to work on multiple branches simultaneously without switching directories.

When not to use it

When you don't need isolated working directories or the project does not use Git or DVC.

Security analysis

Safe
Quality score90/100

The skill uses only safe shell commands (mkdir, git, cp, cat) to create git worktrees and copy configuration files. It does not exfiltrate data, execute destructive operations, or disable safety measures. No external tools are required beyond standard git and shell utilities.

No concerns found

How this analysis is made

Examples

Create worktree for new feature branch
Create a git worktree for a new branch called feature/add-login
Create worktree for existing branch
Set up a worktree for an existing branch named fix/issue-42
Multiple worktree setup
I need to work on multiple branches simultaneously. Please create a worktree for bugfix/error-handling

name: worktree description: This skill should be used when the user asks to "create a worktree", "add a worktree", "set up a worktree", mentions "git worktree", or wants to work on multiple branches simultaneously. user-invocable: true

Create Git Worktree

This skill creates git worktrees in a standardized location with proper DVC configuration.

When to Use

Use this skill when the user:

  • Asks to create a new git worktree
  • Wants to work on multiple branches simultaneously
  • Mentions "git worktree add" or similar

Worktree Location

All worktrees are created under .worktrees/ in the repository root:

repo/
├── .worktrees/
│   ├── feature-branch-1/
│   └── feature-branch-2/
├── src/
└── ...

Instructions

1. Determine the Repository Root

Find the git repository root:

git rev-parse --show-toplevel

2. Create the Worktrees Directory

Ensure the .worktrees directory exists:

mkdir -p "$(git rev-parse --show-toplevel)/.worktrees"

3. Create the Worktree

Create the worktree with the specified branch:

REPO_ROOT="$(git rev-parse --show-toplevel)"
git worktree add "$REPO_ROOT/.worktrees/<branch-name>" <branch-name>

If creating a new branch:

git worktree add -b <new-branch-name> "$REPO_ROOT/.worktrees/<new-branch-name>"

4. Copy .env File

Copy .env from the project root to the worktree so environment variables are available:

REPO_ROOT="$(git rev-parse --show-toplevel)"
WORKTREE_PATH="$REPO_ROOT/.worktrees/<branch-name>"

# Copy .env if it exists
[ -f "$REPO_ROOT/.env" ] && cp "$REPO_ROOT/.env" "$WORKTREE_PATH/"

5. Handle DVC Configuration (if applicable)

Check if the repository uses DVC by looking for .dvc/ directory:

if [ -d "$(git rev-parse --show-toplevel)/.dvc" ]; then
    echo "DVC detected"
fi

If DVC is present and .dvc/config.local exists, copy and update it:

  1. Copy the local config:
REPO_ROOT="$(git rev-parse --show-toplevel)"
WORKTREE_PATH="$REPO_ROOT/.worktrees/<branch-name>"
cp "$REPO_ROOT/.dvc/config.local" "$WORKTREE_PATH/.dvc/config.local"
  1. Update the cache directory to point to the main repo's cache:
REPO_ROOT="$(git rev-parse --show-toplevel)"
WORKTREE_PATH="$REPO_ROOT/.worktrees/<branch-name>"
cat > "$WORKTREE_PATH/.dvc/config.local" << EOF
[cache]
    dir = $REPO_ROOT/.dvc/cache
EOF

Note: If the original .dvc/config.local contains other settings beyond cache configuration, preserve those settings and only update/add the cache dir setting.

Complete Example

Creating a worktree for branch feature/new-api:

REPO_ROOT="$(git rev-parse --show-toplevel)"
BRANCH_NAME="feature/new-api"
WORKTREE_DIR="$REPO_ROOT/.worktrees/$BRANCH_NAME"

mkdir -p "$REPO_ROOT/.worktrees"
git worktree add "$WORKTREE_DIR" "$BRANCH_NAME"

# Copy .env if it exists
[ -f "$REPO_ROOT/.env" ] && cp "$REPO_ROOT/.env" "$WORKTREE_DIR/"

if [ -f "$REPO_ROOT/.dvc/config.local" ]; then
    mkdir -p "$WORKTREE_DIR/.dvc"
    cat > "$WORKTREE_DIR/.dvc/config.local" << EOF
[cache]
    dir = $REPO_ROOT/.dvc/cache
EOF
fi

echo "Worktree created at: $WORKTREE_DIR"

Notes

  • Worktree names typically match branch names, with slashes replaced by the filesystem
  • The .worktrees/ directory should be added to .gitignore if not already
  • Use git worktree list to see all worktrees
  • Use git worktree remove <path> to remove a worktree

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/create-git-worktree-mmbizkpy/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/create-git-worktree-mmbizkpy' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/create-git-worktree-mmbizkpy/download' --output '.skill-downloads/create-git-worktree-mmbizkpy/SKILL.md.part' && mv '.skill-downloads/create-git-worktree-mmbizkpy/SKILL.md.part' '.skill-downloads/create-git-worktree-mmbizkpy/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/create-git-worktree-mmbizkpy/SKILL.md' && test -s '.skill-downloads/create-git-worktree-mmbizkpy/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/worktree' && cp -R '.skill-downloads/create-git-worktree-mmbizkpy' '.claude/skills/worktree'

Cursor
test -f '.skill-downloads/create-git-worktree-mmbizkpy/SKILL.md' && test -s '.skill-downloads/create-git-worktree-mmbizkpy/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/worktree' && cp -R '.skill-downloads/create-git-worktree-mmbizkpy' '.cursor/skills/worktree'

Codex
test -f '.skill-downloads/create-git-worktree-mmbizkpy/SKILL.md' && test -s '.skill-downloads/create-git-worktree-mmbizkpy/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/worktree' && cp -R '.skill-downloads/create-git-worktree-mmbizkpy' '.agents/skills/worktree'

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/create-git-worktree-mmbizkpy'

openskills read 'create-git-worktree-mmbizkpy'

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/create-git-worktree-mmbizkpy/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