AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Using Git Worktrees

skill-hdprajwal-agent-skills-using-git-worktrees · by hdprajwal

Make sure work happens in an isolated workspace before a feature or plan. A feature branch is the default and is enough for most work; reach for a worktree only when you need a second checkout at once (parallel agents, comparing branches, long build running). Detects existing isolation, prefers the harness's native worktree tool, falls back to git, verifies a clean baseline.

No reviews yet
0 installs
13 views
0.0% view→install

Install

$ agentstack add skill-hdprajwal-agent-skills-using-git-worktrees

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-hdprajwal-agent-skills-using-git-worktrees)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
1mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Using Git Worktrees? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Isolated Workspaces (Branches & Worktrees)

Work should never land directly on main. The default is a feature branch — that's what fits the usual loop (branch → fix → PR → merge → delete → next). A worktree is for when you genuinely need two checkouts at once: running parallel agents on independent tasks, comparing branches side by side, or keeping a long build/test going while you work elsewhere. If you don't need a second checkout, a branch is simpler — don't over-engineer it.

Say at the start: "Setting up an isolated workspace."

Branch (default)

git switch -c      # never start on main/master

That's it for most work. Skip the rest unless you actually need a second checkout.

Worktree (when you need a second checkout)

Step 0 — detect existing isolation

GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)

GIT_DIR != GIT_COMMON is also true inside a submodule, so guard:

git rev-parse --show-superproject-working-tree 2>/dev/null  # path = submodule
  • GIT_DIR != GIT_COMMON, not a submodule: already in a worktree — skip to

Setup. Don't nest another.

  • Otherwise: normal checkout. If the user hasn't stated a preference, ask

before creating one.

Step 1 — create it

Native tool first. If the harness has a worktree tool (something like EnterWorktree, a /worktree command, or a --worktree flag), use it — it handles placement, branch, and cleanup, and the harness can track it. Using git worktree add when a native tool exists creates phantom state it can't see.

Git fallback (only if no native tool). Default dir .worktrees/ (else worktrees/; if both, .worktrees/). Project-local dirs MUST be git-ignored first or their contents get committed:

git check-ignore -q .worktrees || { echo ".worktrees/" >> .gitignore && git add .gitignore && git commit -m "chore: ignore worktrees"; }
git worktree add ".worktrees/" -b ""
cd ".worktrees/"

If git worktree add fails on a sandbox permission error, tell the user and work in place.

Setup

Auto-detect and run:

[ -f pnpm-lock.yaml ]   && pnpm install
[ -f package.json ]     && [ ! -f pnpm-lock.yaml ] && npm install
[ -f Cargo.toml ]       && cargo build
[ -f go.mod ]           && go mod download
[ -f pyproject.toml ]   && (poetry install || pip install -e .)

Verify a clean baseline

Run the test command (pnpm test / cargo test / go test ./...).

  • Fail: report and ask whether to proceed — otherwise you can't tell new bugs

from pre-existing ones.

  • Pass: report ready.

Never

  • Start work on main/master.
  • Spin up a worktree when a branch is all you need.
  • Use git worktree add when a native worktree tool exists.
  • Create a project-local worktree without verifying it's ignored.
  • Skip the baseline test, or push through failures without asking.

Source & license

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

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

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.