← ClaudeAtlas

using-git-worktreeslisted

Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via the harness's native worktree tool or a git worktree fallback, with detection-first and safety verification
minhtran3124/agent-harness · ★ 3 · AI & Automation · score 59
Install: claude install-skill minhtran3124/agent-harness
# Using Git Worktrees ## Overview Ensure work happens in an isolated workspace. **Detect existing isolation first. Then prefer the harness's native worktree tool. Fall back to manual `git worktree` only when no native tool exists.** Worktrees share the same repository, allowing work on multiple branches without switching. **Core principle:** Detect → native tool → git fallback. Never fight the harness. **Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace." ## Step 0: Detect Existing Isolation **Before creating anything, check whether you are already in an isolated workspace** — otherwise you risk nesting a worktree inside a worktree. ```bash 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) BRANCH=$(git branch --show-current) ``` **Submodule guard:** `GIT_DIR != GIT_COMMON` is *also* true inside a git submodule. Before concluding "already in a worktree," verify you are not in a submodule: ```bash # If this prints a path, you are in a submodule, not a worktree — treat as a normal repo. git rev-parse --show-superproject-working-tree 2>/dev/null ``` - **If `GIT_DIR != GIT_COMMON` (and not a submodule):** you are already in a linked worktree. **Skip creation** — jump to Creation Step 3 (Project Setup). Report: - On a branch: "Already in isolated workspace at `<path>` on branch `<name>`." - Detached HEAD: "Already isolated at `<path>`