C.W.K.
Stream
Lesson 04 of 05 · published

worktree: 병렬 checkout

~18 min · worktree, parallel-work

Level 0Untracked 새싹
0 XP0/47 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

worktree — checkout 여러 개, repo 하나

고전적 방해 이야기: feature/x 에서 작업 중인데 main 에 긴급 버그 fix 필요, 진행 중 코드가 아직 빌드 안 돼서 stash 못 함. 옛 답은 repo 두 번째 clone. 현대 답은 git worktree: 다른 branch 의 여러 checkout 사본 사이 공유되는 단일 .git/. 같은 commit, 같은 hook, 같은 config — 다른 working tree, 나란히.

git worktree add ../repo-hotfix hotfix/login../repo-hotfixhotfix/login checkout 된 새 worktree 생성. 원본 worktree ./repo 는 여전히 feature/x. 디렉토리 변경으로 프로젝트 switch, branch 아니라. 공유된 .git/ 는 어느 worktree 의 commit 도 다른 쪽에서 즉시 보임. git worktree list 가 모든 checkout 표시, git worktree remove ../repo-hotfix 가 작업 끝나면 하나 은퇴.

높은 레버리지 사용 사례 셋. 진행 중 작업 중 hotfix — hotfix 를 worktree 로 분기, 고치고 ship, stash 없이 feature 복귀. 장기 비교 / 빌드 — 옛 commit 의 한 worktree 에서 긴 test 돌리면서 원본에서 새 commit 작업 계속. 동료 PR 리뷰git worktree add ../repo-pr-142 pr/142 가 main branch checkout 안 흔들고 그들 branch 깨끗이 checkout.

함정 둘. 같은 branch 는 worktree 둘에 동시 checkout 못 해 — Git 거부. (정말 read-only 뷰 원하면 git worktree add --detach.) Worktree 가 disk 소비: 각자 full working-tree 사본, 단 자기 .git/objects/ 없이. 거대 repo 는 secondary worktree 의 partial-clone 이나 sparse-checkout 이 큰 공간 절약. CI 통합도 좋음 — Vercel 류 플랫폼이 각 worktree 독립 배포 가능.

Code

흔한 worktree workflow·bash
# 다른 branch 의 새 worktree 추가:
git worktree add ../repo-hotfix hotfix/login

# 특정 commit 에서 worktree (detached HEAD):
git worktree add --detach ../repo-snapshot v1.4.0

# 새 branch 만들면서 worktree 추가:
git worktree add -b feature/profile ../repo-profile main

# 이 repo 의 모든 worktree list:
git worktree list

# 작업 끝난 worktree 은퇴:
git worktree remove ../repo-hotfix

# Worktree 디렉토리 수동 삭제했으면 registry prune:
git worktree prune
Worktree 로 PR 리뷰·bash
# gh 로 PR branch fetch + worktree 생성:
gh pr checkout 142
# 현재 worktree 가 switch 됨. 더 나은 방법:

git fetch origin pull/142/head:pr/142
git worktree add ../repo-pr-142 pr/142
cd ../repo-pr-142
npm install
npm run dev          # 그들 버전 앱 실행
# 리뷰 끝나면:
cd ../repo
git worktree remove ../repo-pr-142
git branch -D pr/142

External links

Exercise

활성 프로젝트에 git worktree add ../repo-side hotfix-test 로 두 번째 worktree. git worktree list 로 둘 다 확인. 새 worktree 에서 commit, 원본 디렉토리로 switch, 거기서 git log 에 commit 나타나는지 확인. git worktree remove 로 worktree 제거. 현재 stash 로 처리하는 workflow 중 worktree 가 더 잘 다룰 거 하나 적어.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.