·터미널 명령어

git worktree

git

쓰는 꼴

git worktree add <path> [<branch>]

같은 저장소에서 두 번째 작업 폴더를 꺼내 클론 없이 두 브랜치를 동시에 다룹니다 — 한 브랜치를 두 곳에 체크아웃할 수는 없고, 폴더를 손으로 지우면 prune까지 목록에 남습니다.

자주 쓰는 옵션

옵션
add <path> <branch>check that branch out into another folder
add -b <new> <path>create a branch and check it out there
listshow every working tree of this repository
remove <path>delete a working tree cleanly
pruneforget trees whose folder you deleted by hand
--detachcheck out a commit without a branch

예시

git worktree add ../hotfix hotfix/login

a second folder on another branch, sharing one .git

git worktree add -b release ../rel main

creates release from main in ../rel

git worktree remove ../hotfix

removes the folder and its bookkeeping entry

되돌리는 방법이 여럿이라 헷갈립니다 — 가리키는 곳을 옮기는 것과 새 커밋을 얹는 것은 다릅니다.

읽는 방법

  • 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
  • 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
  • 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.

자주 묻는 것

Q. git worktree은 무엇을 하나요?

같은 저장소에서 두 번째 작업 폴더를 꺼내 클론 없이 두 브랜치를 동시에 다룹니다 — 한 브랜치를 두 곳에 체크아웃할 수는 없고, 폴더를 손으로 지우면 prune까지 목록에 남습니다.

Q. 어떻게 치나요?

git worktree add <path> [<branch>] — 대괄호는 생략할 수 있는 자리입니다.

Q. 옵션은 몇 개나 자주 쓰나요?

여기 정리한 것은 6개입니다. 전체 목록은 man git에 있습니다. 이 명령은 git 갈래입니다.

같이 보는 명령

man 페이지: man git-worktree