핵심 요약
일반적인 Git 명령(checkout·pull·merge)으로 풀리지 않는 상황이 있다. 동시 브랜치 작업, 모노레포에서 일부 디렉토리만 받기, 거대 저장소를 빠르게 시작하기. 이 글은 worktree·sparse-checkout·partial clone·cone mode 4가지를 실전 예시로 정리한다.
1. git worktree — 동시 브랜치 작업
main 브랜치 작업 중에 hotfix 브랜치를 동시에 보고 싶을 때. stash + checkout은 컨텍스트 전환 비용이 크다. worktree는 동일 저장소를 다른 디렉토리에 추가 체크아웃.
# main 브랜치 작업 중
$ pwd
/home/user/myproject # main
# hotfix 브랜치를 별도 디렉토리에 체크아웃
$ git worktree add ../myproject-hotfix hotfix-1234
# 새 디렉토리로 이동, 별도 IDE 창에서 작업 가능
$ cd ../myproject-hotfix
$ # 작업 후
$ git push origin hotfix-1234
# 작업 종료 후 정리
$ cd ../myproject
$ git worktree remove ../myproject-hotfixworktree들은 같은 .git을 공유하므로 디스크 효율적. fetch·branch는 한 곳에서 하면 모두 반영.
2. sparse-checkout — 모노레포 부분만
모노레포에서 packages/ui만 작업할 때, 전체 저장소 (~10GB)를 받지 않고 필요한 부분만:
# clone 시 blob 받지 않음
$ git clone --filter=blob:none --no-checkout https://github.com/big-org/monorepo
$ cd monorepo
# sparse-checkout 활성화 (cone mode)
$ git sparse-checkout init --cone
$ git sparse-checkout set packages/ui packages/utils
# 이제 packages/ui와 packages/utils만 체크아웃
$ git checkout maincone mode란?
cone mode는 디렉토리 단위로만 sparse-checkout 패턴을 허용 (전통 모드는 glob 패턴 가능하지만 느림). 빠르고 직관적.
3. partial clone — 큰 저장소 빠르게 받기
Linux 커널·Chromium 같은 거대 저장소를 받을 때:
# blob (실제 파일 내용)을 lazy fetch
$ git clone --filter=blob:none https://github.com/torvalds/linux
# 평균 30초 (전체 clone은 30분+)
# 파일을 처음 read하면 그때 다운로드
$ cd linux
$ cat README # 첫 read 시 0.3초 정도 추가 지연combination: --filter=blob:none --filter=tree:0는 트리도 lazy. CI 환경에서 매우 효과 큼.
4. git rebase --autostash·--autosquash
커밋을 깔끔하게 정리하는 흔한 패턴.
# autostash: 작업 중인 변경을 자동 stash하고 rebase 후 복원
$ git rebase --autostash main
# autosquash: !fixup·!squash 메시지 자동 처리
$ git commit --fixup HEAD~3
$ git rebase -i --autosquash main
# 자동으로 fixup이 정리됨5. 실전 — worktree로 long-running 작업 분리
큰 PR 리뷰 + 자기 작업 동시:
# 메인 디렉토리: 자기 feature 작업
$ pwd ; git branch --show-current
/home/user/proj feature-payment
# review용 worktree 추가
$ git worktree add ../proj-review pr-1234
$ cd ../proj-review
$ # 리뷰어 코드 직접 실행
$ npm install && npm test
# 동시에 다른 터미널에서 자기 작업 계속
$ cd ~/proj
$ npm run dev6. .gitignore보다 강력한 .git/info/exclude
로컬에만 무시할 파일은 .gitignore에 추가하면 다른 사람에게도 영향. .git/info/exclude는 로컬 한정.
$ echo ".vscode/settings.json" >> .git/info/exclude7. reflog로 잃어버린 작업 복구
# 실수로 reset --hard 후
$ git reflog
abc1234 HEAD@{0}: reset: moving to HEAD~3
def5678 HEAD@{1}: commit: 잃어버린 작업
# def5678 시점으로 복구
$ git reset --hard def5678reflog는 90일 보존 (기본). 그 안엔 거의 모든 실수 복구 가능.
실무 추천 별칭
# ~/.gitconfig
[alias]
co = checkout
br = branch
st = status -sb
last = log -1 HEAD
unstage = reset HEAD --
visual = log --graph --oneline --all
amend = commit --amend --no-edit
wt = worktree
# 가장 자주 쓰는: stash + clean + status
fresh = !git stash && git clean -fd자주 묻는 질문
worktree와 그냥 별도 clone의 차이?
worktree는 .git을 공유 → 디스크 효율적, fetch·tag 동기화 자동. 별도 clone은 완전 독립 → 무거움.
partial clone이 항상 빠른가?
처음 clone은 빠름. 하지만 git log·grep 등이 lazy fetch 트리거하면 한 번 느림. 자주 쓰는 작업은 결국 받아야 함.
sparse-checkout과 git submodule 차이?
submodule은 별도 저장소 참조. sparse-checkout은 같은 저장소의 일부. 모노레포 구조라면 sparse-checkout, 의존성 관리라면 submodule.

댓글 0