Using git worktrees
Skill ComeOnOliver/skillshub/skills/aiskillstore/marketplace/doyajin174/using-git-worktrees
๐ง The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.
npx -y skills add ComeOnOliver/skillshub --skill using-git-worktreesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
What its author says it does
Copied from the file, not written here
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.
The file declares its own license as MIT. That is the authorโs claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
3.9 KB, as published. Nobody here has run it
Using Git Worktrees
Git worktree๋ฅผ ์ฌ์ฉํ ๊ฒฉ๋ฆฌ๋ ๊ฐ๋ฐ ํ๊ฒฝ ์์ฑ ๊ฐ์ด๋์ ๋๋ค.
When to Use
- ๊ธฐ๋ฅ ๊ฐ๋ฐ์ ์ํ ๊ฒฉ๋ฆฌ๋ ํ๊ฒฝ ํ์ ์
- ์ฌ๋ฌ ๋ธ๋์น์์ ๋์ ์์ ์
- ์์ ํ ์คํ์ด ํ์ํ ๋
- ๊ตฌํ ๊ณํ ์คํ ์ ํ๊ฒฝ ์ค๋น ์
Quick Start
# 1. worktree ๋๋ ํ ๋ฆฌ ํ์ธ/์์ฑ
ls -la ../worktrees/ 2>/dev/null || mkdir -p ../worktrees
# 2. ์ worktree ์์ฑ
git worktree add ../worktrees/feature-name -b feature/feature-name
# 3. worktree๋ก ์ด๋
cd ../worktrees/feature-name
# 4. ์์
์๋ฃ ํ ์ ๋ฆฌ
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
์์ฑ ์ ์ฒดํฌ๋ฆฌ์คํธ
# 1. ํ์ฌ ์ํ ํ์ธ
git status # ๋ฏธ์ปค๋ฐ ๋ณ๊ฒฝ์ฌํญ ํ์ธ
git stash list # stash ์ํ ํ์ธ
# 2. ๋ธ๋์น ์กด์ฌ ์ฌ๋ถ ํ์ธ
git branch -a | grep feature-name
# 3. worktree ๋ชฉ๋ก ํ์ธ
git worktree list
์์ฑ ํ ๊ฒ์ฆ
# 1. worktree ์ํ ํ์ธ
git worktree list
# 2. ํ์ฌ ๋ธ๋์น ํ์ธ
git branch
# 3. ์๊ฒฉ ์ฐ๊ฒฐ ํ์ธ
git remote -v
Common Workflows
๊ธฐ๋ฅ ๊ฐ๋ฐ ์์
# 1. ์ต์ main ๊ธฐ์ค์ผ๋ก worktree ์์ฑ
git fetch origin
git worktree add ../worktrees/feature-x -b feature/x origin/main
# 2. ์์กด์ฑ ์ค์น (ํ๋ก์ ํธ์ ๋ฐ๋ผ)
cd ../worktrees/feature-x
npm install # ๋๋ pip install -r requirements.txt
# 3. ๊ฐ๋ฐ ์์
code . # ๋๋ ์ํ๋ ์๋ํฐ
์ฝ๋ ๋ฆฌ๋ทฐ์ฉ ํ๊ฒฝ
# PR ๋ธ๋์น๋ฅผ ๋ณ๋ worktree๋ก
git worktree add ../worktrees/review-pr-123 origin/feature/pr-123
cd ../worktrees/review-pr-123
# ํ
์คํธ ์คํ, ์ฝ๋ ๊ฒํ
๊ธด๊ธ ์์
# ํ์ฌ ์์
์ค๋จ ์์ด hotfix
git worktree add ../worktrees/hotfix-critical -b hotfix/critical origin/main
cd ../worktrees/hotfix-critical
# ์์ โ ์ปค๋ฐ โ PR
Cleanup
๊ฐ๋ณ worktree ์ ๊ฑฐ
# 1. worktree ์ ๊ฑฐ
git worktree remove ../worktrees/feature-x
# 2. ๋ธ๋์น๋ ์ญ์ ํ๋ ค๋ฉด
git branch -d feature/x
์ ์ฒด ์ ๋ฆฌ
# 1. ๋ชจ๋ worktree ๋ชฉ๋ก
git worktree list
# 2. ์ ๋ฆฌ (์ญ์ ๋ worktree ์ฐธ์กฐ ์ ๊ฑฐ)
git worktree prune
# 3. ๋ฏธ์ฌ์ฉ worktree ๋๋ ํ ๋ฆฌ ์ญ์
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 ํ ์งํ |