using-git-worktrees
하는 일
AI 에이전트가 기능을 위해 별도의 git worktree나 플랫폼 기본 작업공간을 만들고 쓰도록 안내합니다. 완료되지 않은 작업을 메인 코드 사본과 분리해 두려는 개발자를 위한 스킬입니다.
사용하는 경우
- ✓기능을 시작하면서 현재 작업공간과 분리해 두고 싶을 때.
- ✓구현 계획을 실행하려는데 깔끔한 작업 장소가 필요할 때.
- ✓이미 격리된 작업공간 안에 있는지 확인해야 할 때.
스킬 링크
https://github.com/obra/superpowers/blob/main/skills/using-git-worktrees/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“검색 기능을 위해 별도의 작업공간을 설정해 주세요. 제 메인 코드 사본은 건드리지 마세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 먼저 이미 격리된 작업공간인지 확인합니다. 아니라면 플랫폼의 기본 도구로 작업공간을 만들고, 기본 도구가 없을 때만 수동 git worktree로 대체합니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Using Git Worktrees
Overview
Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.
Core principle: Detect existing isolation first. Then use native tools. Then fall back to git. 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 if you are already in an isolated workspace.
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 git submodules. Before concluding "already in a worktree," verify you are not in a submodule:
# If this returns a path, you're in a submodule, not a worktree — treat as 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 to Step 2 (Project Setup). Do NOT create another worktree.
Report with branch state:
- On a branch: "Already in isolated workspace at
<path>on branch<name>." - Detached HEAD: "Already in isolated workspace at
<path>(detached HEAD, externally managed). Branch creation needed at finish time."
If GIT_DIR == GIT_COMMON (or in a submodule): You are in a normal repo checkout.
Has the user already indicated their worktree preference in your instructions? If not, ask for consent before creating a worktree:
"Would you like me to set up an isolated worktree? It protects your current branch from changes."
Honor any existing declared preference without asking. If the user declines consent, work in place and skip to Step 2.
Step 1: Create Isolated Workspace
You have two mechanisms. Try them in this order.
1a. Native Worktree Tools (preferred)
The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like EnterWorktree, WorktreeCreate, a /worktree command, or a --worktree flag. If you do, use it and skip to Step 2.
Native tools handle directory placement, branch creation, and cleanup automatically. Using git worktree add when you have a native tool creates phantom state your harness can't see or manage.
Only proceed to Step 1b if you have no native worktree tool available.
1b. Git Worktree Fallback
Only use this if Step 1a does not apply — you have no native worktree tool available. Create a worktree manually using git.
Directory Selection
Follow this priority order. Explicit user preference always beats observed filesystem state.
Check your instructions for a declared worktree directory preference. If the user has already specified one, use it without asking.
Check for an existing project-local worktree directory:
ls -d .worktrees 2>/dev/null # Preferred (hidden) ls -d worktrees 2>/dev/null # AlternativeIf found, use it. If both exist,
.worktreeswins.If there is no other guidance available, default to
.worktrees/at the project root.
Safety Verification (project-local directories only)
MUST verify directory is ignored before creating worktree:
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
If NOT ignored: Add to .gitignore, commit the change, then proceed.
Why critical: Prevents accidentally committing worktree contents to repository.
Create the Worktree
# Determine path based on chosen location
path="$LOCATION/$BRANCH_NAME"
git worktree add "$path" -b "$BRANCH_NAME"
cd "$path"
Sandbox fallback: If git worktree add fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.
Step 2: Project Setup
Auto-detect and run appropriate setup:
# Node.js
if [ -f package.json ]; then npm install; 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
Step 3: Verify Clean
자주 묻는 질문
이미 작업공간 안에 있으면 새로 만드나요?
아닙니다. 이미 연결된 worktree 안에 있다면 그렇다고 알리고, 다른 것을 만들지 않습니다.
git 서브모듈도 작업공간으로 보나요?
아닙니다. 서브모듈은 따로 체크아웃되므로, 격리된 작업공간으로 잘못 여기지 않습니다.
대안은 무엇인가요?
기본 작업공간 도구가 없을 때만 수동 git worktree를 씁니다.
상세 정보
작성자의 원본 설명
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
repo: obra/superpowers
인기도
- GitHub 스타
- 311k
- 순위
- #96
- 라이선스
- MIT
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
brainstorming
311k에이전트가 집중된 질문과 분명한 선택지를 통해, 새로운 것을 만들기 전에 사용자가 실제로 원하는 것을 파악하도록 돕습니다.
executing-plans
311k에이전트가 작성된 구현 계획을 현재 세션에서 단계별로 실행하고, 각 단계를 테스트한 뒤 다음으로 넘어가도록 돕습니다.
finishing-a-development-branch
311k에이전트가 완성된 코드의 테스트를 실행한 뒤, 병합, 풀 리퀘스트 열기, 브랜치 유지 중에서 고를 수 있도록 명확한 선택지를 제시하도록 돕습니다.
receiving-code-review
311k에이전트가 코드 리뷰 피드백을 신중하게 검토하도록 돕습니다. 무엇이든 바꾸기 전에 각 지적을 실제 코드와 대조합니다.