Git Worktree logo

Git Worktree

CommunityPopular
FlorianBruniaux
git-worktree

Create isolated git worktrees for feature development without switching branches

Overview

PublisherFlorianBruniaux
Repositoryclaude-code-ultimate-guide
Skill namegit-worktree
Stars
6K
Forks
782
Bundled files
Instructions only
LicenseCC-BY-SA-4.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by FlorianBruniaux on GitHub. Read the source before you install it.

Installation

Install the Git Worktree AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/FlorianBruniaux/claude-code-ultimate-guide.git /tmp/claude-code-ultimate-guide
mkdir -p .claude/skills
cp -r /tmp/claude-code-ultimate-guide/examples/skills/git-worktree .claude/skills/git-worktree
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Git Worktree in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Git Worktree on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Git Worktree is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Git Worktree Setup

Create isolated git worktrees for feature development without switching branches.

Core principle: Smart directory selection + symlink optimization + background verification = fast, reliable isolation.

Requires: Git 2.5.0+ (July 2015)

Companion commands: /git-worktree-status | /git-worktree-remove | /git-worktree-clean

Process

  1. Validate Branch Name: Check naming convention and conflicts
  2. Check Existing Directories: .worktrees/ or worktrees/
  3. Verify .gitignore: Ensure worktree dir is ignored
  4. Create Worktree: git worktree add
  5. Symlink Dependencies: Reuse node_modules/ from main worktree
  6. Detect Database Provider: Check for DB branching capability
  7. Install Dependencies: Auto-detect package manager (if not symlinking)
  8. Run Background Verification: Type check + tests in background
  9. Report Location: Confirm ready with status

Flags

FlagEffect
--fastSkip dependency install and baseline tests
--isolatedFresh node_modules install (no symlink)
--skip-installSkip dependency install, keep baseline tests

Branch Name Validation

bash
# Auto-prefix based on naming convention
# "auth" → "feat/auth" (default prefix)
# "fix/login-bug" → kept as-is
# "refactor/db-layer" → kept as-is

# Accepted prefixes: feat/, fix/, refactor/, chore/, docs/, test/, perf/
# If no prefix → default to feat/

# Reject invalid characters
echo "$BRANCH_NAME" | grep -qE '^[a-zA-Z0-9/_-]+$' || exit 1

# Check branch doesn't already exist
git show-ref --verify --quiet "refs/heads/$BRANCH_NAME" && echo "Branch already exists" && exit 1

Directory Selection

Priority Order

bash
# 1. Check existing directories
ls -d .worktrees 2>/dev/null     # Preferred (hidden)
ls -d worktrees 2>/dev/null      # Alternative

# 2. Check CLAUDE.md for preference
grep -i "worktree.*director" CLAUDE.md 2>/dev/null

# 3. Ask user if neither exists

If both exist: .worktrees/ wins.

Safety Verification

For project-local directories:

bash
# Check if directory in .gitignore
grep -q "^\.worktrees/$" .gitignore || grep -q "^worktrees/$" .gitignore

If NOT in .gitignore:

  1. Add line to .gitignore
  2. Commit the change
  3. Proceed with worktree creation

Why critical: Prevents accidentally committing worktree contents.

Creation Steps

bash
# 1. Detect project name
project=$(basename "$(git rev-parse --show-toplevel)")

# 2. Create worktree with new branch
git worktree add .worktrees/$BRANCH_NAME -b $BRANCH_NAME

# 3. Navigate
cd .worktrees/$BRANCH_NAME

Dependency Optimization (Node.js)

Default behavior: Symlink node_modules from main worktree to avoid duplicate installs (~30s saved).

bash
# Symlink node_modules (default, unless --isolated)
if [ -d "../../node_modules" ] && [ ! "$ISOLATED" = true ]; then
  ln -s "$(cd ../.. && pwd)/node_modules" node_modules
  echo "Symlinked node_modules from main worktree"
fi

# With --isolated: fresh install
if [ "$ISOLATED" = true ]; then
  pnpm install   # or npm/yarn based on lockfile detection
fi

When to use --isolated:

  • Schema changes requiring different package versions
  • Testing dependency upgrades
  • Debugging node_modules issues

Auto-Detect Setup (Multi-Stack)

bash
# Node.js (if not symlinked)
if [ -f package.json ] && [ ! -L node_modules ]; then
  pnpm install   # Detect from lockfile: pnpm-lock.yaml / yarn.lock / package-lock.json
fi

# Rust
if [ -f Cargo.toml ]; then cargo build; fi

# Python
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f pyproject.toml ]; then poetry install; fi

# Go
if [ -f go.mod ]; then go mod download; fi

Background Verification

Instead of blocking on full test suite, run verification in background:

bash
# Create log directory
mkdir -p .worktree-logs

# Background type check (Node.js)
if [ -f tsconfig.json ]; then
  npx tsc --noEmit > .worktree-logs/typecheck.log 2>&1 &
  echo "Type check running in background (check with /git-worktree-status)"
fi

# Background test run
if [ -f package.json ]; then
  npx vitest run --reporter=json > .worktree-logs/tests.log 2>&1 &
  echo "Tests running in background (check with /git-worktree-status)"
fi

With --fast: Skip all verification.

Final Report

Worktree ready at <full-path>
Branch: feat/auth (created from main)
Dependencies: symlinked from main worktree
Background checks: type check + tests running
Check status: /git-worktree-status

Ready to implement <feature-name>

Database Branch Suggestion

After worktree creation, detect database provider and suggest isolation.

Quick Command Reference

ProviderSuggested Command
Neonneonctl branches create --name <branch> --parent main
PlanetScalepscale branch create <db> <branch>
Local Postgrespsql -c "CREATE SCHEMA <schema>;"
OtherManual setup or shared DB

Example output:

Worktree created at .worktrees/feat/auth

DB Isolation: neonctl branches create --name feat-auth --parent main
   Then update .env with new DATABASE_URL
   Full guide: ../workflows/database-branch-setup.md

.worktreeinclude Setup

Critical for environment variables:

bash
# .worktreeinclude (at project root)
.env
.env.local
.env.development
**/.claude/settings.local.json

Why: Without this, .env files won't be copied to worktrees.

When to Create Database Branch

ScenarioCreate Branch?
Schema migrationsYes
Data model refactoringYes
Bug fix (no schema change)No
Performance experimentsYes

See: Database Branch Setup Guide for complete workflows.

Quick Reference

SituationAction
.worktrees/ existsUse it (verify .gitignore)
worktrees/ existsUse it (verify .gitignore)
Both existUse .worktrees/
Neither existsCheck CLAUDE.md, then ask user
Not in .gitignoreAdd + commit immediately
No branch prefixAuto-prefix with feat/
Node.js projectSymlink node_modules by default
--fast flagSkip install + tests
--isolated flagFresh node_modules install
Neon detectedSuggest neonctl branches create
PlanetScale detectedSuggest pscale branch create
No .worktreeincludeCreate with .env pattern

Common Mistakes

Skipping .gitignore verification

  • Worktree contents get tracked, pollute git status

Assuming directory location

  • Follow priority: existing > CLAUDE.md > ask

Installing full node_modules in every worktree

  • Wastes disk and time. Use symlink by default, --isolated only when needed

Not copying .env to worktree

  • Symptom: Claude fails with "DATABASE_URL not found"
  • Fix: Add .env to .worktreeinclude

Using shared database for schema changes

  • Symptom: Migration conflicts, broken dev environment
  • Fix: Create database branch before modifying schema

Usage

/git-worktree auth
/git-worktree fix/session-bug
/git-worktree feature/new-api --fast
/git-worktree refactor/db-layer --isolated

Branch name: $ARGUMENTS

Frequently asked questions

What does the Git Worktree AI skill do?

Create isolated git worktrees for feature development without switching branches

Why use Git Worktree on TypingMind?

Because you install it once and use it with any model. Git Worktree is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Git Worktree in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/FlorianBruniaux/claude-code-ultimate-guide/tree/main/examples/skills/git-worktree. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Git Worktree?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Git Worktree?

As many as you like. As long as a model supports skills, you can use Git Worktree with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Git Worktree AI skill free?

Yes. It is published on GitHub by FlorianBruniaux under the CC-BY-SA-4.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇