Use Git Worktree logo

Use Git Worktree

Community
etr
use-git-worktree

This skill should be used when starting feature work that needs isolation from current workspace - creates isolated git worktrees with smart directory selection and safety verification

Overview

Publisheretr
Repositorygroundwork
Skill nameuse-git-worktree
Stars
45
Forks
4
Bundled files
Instructions only
LicenseMIT
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 etr on GitHub. Read the source before you install it.

Installation

Install the Use 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.
    https://github.com/etr/groundwork/tree/main/skills/use-git-worktree
  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/etr/groundwork.git /tmp/groundwork
mkdir -p .claude/skills
cp -r /tmp/groundwork/skills/use-git-worktree .claude/skills/use-git-worktree
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Use 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 Use 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 Use 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 Management

Create and manage isolated git worktrees for task execution with automatic project setup and merge handling.

Overview

Git worktrees provide complete isolation for task work:

  • Changes don't affect main workspace until merge
  • Can switch between tasks without stashing
  • Clean baseline for each task
  • Safe to experiment

Workflow

Step 1: Determine Worktree Directory

Find or create the worktree directory using this priority order:

  1. Check for existing directory:

    bash
    # Preferred (hidden, less clutter)
    ls -d .worktrees 2>/dev/null
    # Alternative
    ls -d worktrees 2>/dev/null
  2. Check CLAUDE.md for directive:

    markdown
    worktree-dir: path/to/worktrees
  3. Check README.md for configuration: Look for worktree or development setup instructions.

  4. Ask user if not found:

    "Where should I create worktrees for isolated task work?

    1. .worktrees/ (Recommended - hidden, less clutter)
    2. worktrees/
    3. Custom location"

Step 2: Verify Directory is Gitignored

Critical: Ensure the worktree directory won't be committed.

bash
git check-ignore -q <worktree-dir>

If not ignored:

  • Add to .gitignore with user confirmation
  • Report the change
bash
echo "<worktree-dir>/" >> .gitignore

Step 3: Create Branch and Worktree

Resolve the workspace identity with the shared helper — never derive it by hand.

Task IDs are only unique per project (each project numbers its own specs/tasks.md), so the branch and worktree path must be project-qualified in monorepos. The helper applies the same convention the terminal runner uses, so interactive sessions and runner runs share one identity space and can never silently collide:

bash
node ${CLAUDE_PLUGIN_ROOT}/lib/worktree-identity.js TASK-004

Output (single JSON line):

json
{"task_id":"TASK-004","repo_root":"…","project_root":"…","project_name":"web",
 "scope":"project","path":"<repo>/.worktrees/web-TASK-004","branch":"task/web/TASK-004",
 "legacy":{"path":"<repo>/.worktrees/TASK-004","branch":"task/TASK-004","exists":false,"runner_owner":null}}

Rules:

  • Use the returned path and branch verbatim — including in merges, cleanup, and reports. Single-project repos get the short form (task/TASK-004, <dir>/TASK-004); monorepos get the project-qualified form.
  • If legacy.exists is true, a pre-scoping unqualified worktree exists at the repository root: surface it to the user ("if it belongs to another project, remove it; if it's yours, continue working in it") instead of silently adopting or ignoring it.
  • If legacy.runner_owner names a project, that legacy worktree is owned by a runner run's checkpoint — do not reuse it without the user's explicit confirmation.

Create from current HEAD:

bash
# Get current branch as base
BASE_BRANCH=$(git branch --show-current)

# Create branch and worktree in one command, using the helper's values
git worktree add -b <branch> <worktree-path>

Record context (used by every later merge/cleanup step):

  • Base branch (for later merge)
  • Worktree path (<worktree-path>)
  • Branch (<branch>)
  • Task ID

Step 4: Auto-Detect and Run Project Setup

Change to worktree directory and detect project type:

File PresentSetup Command
package.jsonnpm install or yarn install
Cargo.tomlcargo build
requirements.txtpip install -r requirements.txt
Pipfilepipenv install
pyproject.tomlpip install -e . or poetry install
go.modgo mod download
Gemfilebundle install
pom.xmlmvn install
build.gradle./gradlew build

Check for custom setup:

  1. Read CLAUDE.md for setup instructions
  2. Read README.md for development setup section
  3. Execute any documented setup steps

Step 5: Verify Baseline Tests Pass

Run the project's test suite to ensure a clean starting point:

bash
# Detect test command from package.json, Makefile, etc.
npm test          # Node.js
cargo test        # Rust
pytest            # Python
go test ./...     # Go
bundle exec rspec # Ruby

If tests fail:

"Baseline tests are failing in the worktree. This may indicate:

  1. Setup incomplete - check dependencies
  2. Tests require specific environment
  3. Base branch has failing tests

Would you like to:

  1. Continue anyway (tests may already be failing)
  2. Abort and investigate"

Step 6: Return Worktree Context

Provide context for the calling skill:

markdown
## Worktree Created

**Task:** TASK-NNN
**Branch:** <branch from the helper>
**Base Branch:** main
**Working Directory:** <worktree-path from the helper>
**Merge Mode:** [auto-merge|manual]

Project setup complete. Baseline tests passing.

Ready to begin work.

Merge Operations

Auto-Merge Flow

When task completes with auto-merge enabled:

bash
# Ensure all changes committed in worktree
cd <worktree-path>
git status --porcelain  # Should be empty

# Return to main repo and merge (branch/worktree-path as recorded in Step 3)
cd <original-repo>
git checkout <base-branch>
git merge --no-ff <task-branch> -m "Merge <task-branch>: [Task Title]"

# Cleanup
git worktree remove <worktree-path>
git branch -d <task-branch>

Manual Verification Flow

When user wants to review before merge:

markdown
## Task Complete in Worktree

**Location:** <worktree-path>
**Branch:** <task-branch>

All changes committed. To merge manually:
```bash
git checkout <base-branch>
git merge --no-ff <task-branch>
git worktree remove <worktree-path>
git branch -d <task-branch>

Or to continue working:

bash
cd <worktree-path>

### Merge Conflict Handling

If merge conflicts occur:

```markdown
## Merge Conflict

The merge of <task-branch> into <base-branch> has conflicts.

**Conflicting files:**
- path/to/file1.ts
- path/to/file2.ts

**Options:**
1. Resolve conflicts manually in the main repo
2. Abort merge and keep worktree for investigation

**To resolve:**
```bash
# In main repo after failed merge
git status                    # See conflicting files
# Edit files to resolve conflicts
git add <resolved-files>
git commit                    # Complete merge

# Then cleanup
git worktree remove <worktree-path>
git branch -d <task-branch>

To abort:

bash
git merge --abort
# Worktree preserved at <worktree-path>

## Error Handling

| Error | Recovery |
|-------|----------|
| Branch already exists | Another session (or a runner run) may hold this task — run `git worktree list`, offer to reuse the existing worktree, wait, or clean it up |
| Worktree path exists | Check if it's valid, offer cleanup or different path |
| Not a git repository | Cannot use worktrees, fall back to current directory |
| Uncommitted changes | Prompt to commit or stash before creating worktree |
| Setup command fails | Report error, offer to continue or abort |

## Cleanup Commands

**Remove a worktree:**
```bash
git worktree remove <path>
git branch -d <branch>  # Safe delete (checks merge status)
git branch -D <branch>  # Force delete

List all worktrees:

bash
git worktree list

Prune stale worktrees:

bash
git worktree prune

Frequently asked questions

What does the Use Git Worktree AI skill do?

This skill should be used when starting feature work that needs isolation from current workspace - creates isolated git worktrees with smart directory selection and safety verification

Why use Use Git Worktree on TypingMind?

Because you install it once and use it with any model. Use 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 Use Git Worktree in TypingMind?

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

Which AI models can use 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 Use Git Worktree?

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

Is the Use Git Worktree AI skill free?

Yes. It is published on GitHub by etr under the MIT 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 👇