# Using Git Worktrees

> Use when starting feature work that needs isolation from the current workspace, or before executing implementation plans — ensures an isolated workspace exists via native worktree tools or git worktree fallback.

- **Type:** Skill
- **Install:** `agentstack add skill-skywalkercyt-mp-implement-using-git-worktrees`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [skywalkercyt](https://agentstack.voostack.com/s/skywalkercyt)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [skywalkercyt](https://github.com/skywalkercyt)
- **Source:** https://github.com/skywalkercyt/mp-implement/tree/main/skills/using-git-worktrees

## Install

```sh
agentstack add skill-skywalkercyt-mp-implement-using-git-worktrees
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Using Git Worktrees

> **Adapted skill** — discipline originating in Superpowers v5.1.0 (MIT, Jesse Vincent), rewritten in mattpocock-skills style. Used by `/mp-implement-issue` step 3 and both pipelines' Phase 3 to give each slice an isolated workspace.

Isolate the work before touching code: detect existing isolation first, use the harness's native worktree tool if one exists, fall back to `git worktree` only without one.

## 1. Detect existing isolation

Run detection before creating anything.

```bash
GIT_DIR=$(cd "$(git rev-parse --git-dir)" && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" && pwd -P)
git rev-parse --show-superproject-working-tree 2>/dev/null
```

- `GIT_DIR != GIT_COMMON` and the superproject check prints nothing → already in a linked worktree; skip to setup (step 3). On detached HEAD, note the worktree is externally managed and branch creation happens at finish time.
- The superproject check prints a path → you're in a submodule; treat it as a normal repo.

In a normal checkout, honor any declared worktree preference without asking. With none declared, ask one consent question; declined → work in place and skip to setup.

## 2. Create the worktree

**Native tool first.** If the harness offers one (`EnterWorktree`-style tool, `/worktree` command, `--worktree` flag), use it — it manages placement, branching, and cleanup that the git fallback leaves to you. Then skip to setup.

**Git fallback** — only with no native tool. Directory priority: declared preference > existing `.worktrees/` or `worktrees/` (`.worktrees/` wins if both) > default `.worktrees/` at the repo root.

Verify the directory is git-ignored before creating:

```bash
git check-ignore -q  || echo "/" >> .git/info/exclude
```

```bash
git worktree add .worktrees/ -b 
cd .worktrees/
```

A permission error here means the sandbox blocked creation — say so, then run setup and baseline in place.

## 3. Setup

Auto-detect and install:

```bash
[ -f package.json ] && npm install
[ -f Cargo.toml ] && cargo build
[ -f requirements.txt ] && pip install -r requirements.txt
[ -f pyproject.toml ] && poetry install
[ -f go.mod ] && go mod download
```

## 4. Baseline

Run the project test suite (`npm test` / `cargo test` / `pytest` / `go test ./...`). Green before any work begins; red → report the failures and stop — never start from a broken baseline.

## Report

```
Worktree ready at  on branch 
Tests passing ( tests, 0 failures)
Ready to implement 
```

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [skywalkercyt](https://github.com/skywalkercyt)
- **Source:** [skywalkercyt/mp-implement](https://github.com/skywalkercyt/mp-implement)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-skywalkercyt-mp-implement-using-git-worktrees
- Seller: https://agentstack.voostack.com/s/skywalkercyt
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
