| name | using-git-worktrees |
| description | Create isolated git worktrees with smart directory selection and safety verification. Use this when starting feature work that needs isolation, parallel development, or safe experimentation. |
| allowed-tools | Read, Glob, Grep, Bash |
| license | MIT |
| metadata | {"author":"obra/superpowers","version":"1.0"} |
Using Git Worktrees
Git worktree를 사용한 격리된 개발 환경 생성 가이드입니다.
When to Use
- 기능 개발을 위한 격리된 환경 필요 시
- 여러 브랜치에서 동시 작업 시
- 안전한 실험이 필요할 때
- 구현 계획 실행 전 환경 준비 시
Quick Start
ls -la ../worktrees/ 2>/dev/null || mkdir -p ../worktrees
git worktree add ../worktrees/feature-name -b feature/feature-name
cd ../worktrees/feature-name
git worktree remove ../worktrees/feature-name
Directory Selection Strategy
권장 구조
project-root/
├── .git/ # 메인 저장소
├── src/ # 메인 작업 디렉토리
└── ...
../worktrees/ # worktree 전용 디렉토리
├── feature-auth/ # 인증 기능 작업
├── feature-api/ # API 개발
└── hotfix-critical/ # 긴급 수정
네이밍 규칙
../worktrees/{type}-{name}
types:
- feature-* 기능 개발
- hotfix-* 긴급 수정
- experiment-* 실험적 변경
- review-* 코드 리뷰용
Safety Verification
생성 전 체크리스트
git status
git stash list
git branch -a | grep feature-name
git worktree list
생성 후 검증
git worktree list
git branch
git remote -v
Common Workflows
기능 개발 시작
git fetch origin
git worktree add ../worktrees/feature-x -b feature/x origin/main
cd ../worktrees/feature-x
npm install
code .
코드 리뷰용 환경
git worktree add ../worktrees/review-pr-123 origin/feature/pr-123
cd ../worktrees/review-pr-123
긴급 수정
git worktree add ../worktrees/hotfix-critical -b hotfix/critical origin/main
cd ../worktrees/hotfix-critical
Cleanup
개별 worktree 제거
git worktree remove ../worktrees/feature-x
git branch -d feature/x
전체 정리
git worktree list
git worktree prune
rm -rf ../worktrees/old-feature
git worktree prune
Best Practices
- 일관된 위치: worktree는 항상
../worktrees/에
- 명확한 네이밍: 목적이 드러나는 이름 사용
- 정기적 정리: 완료된 worktree는 즉시 제거
- 독립적 의존성: 각 worktree에서 별도로 의존성 설치
- 메인 저장소 보존: worktree에서만 실험적 변경
Troubleshooting
| 문제 | 해결책 |
|---|
| "already checked out" | 다른 worktree에서 사용 중, 다른 브랜치명 사용 |
| "not a valid ref" | git fetch 먼저 실행 |
| 의존성 오류 | worktree에서 새로 설치 필요 |
| 변경사항 충돌 | 메인에서 stash 또는 commit 후 진행 |