현재 해당 브랜치({branch})로 체크아웃된 상태에서 해당 브랜치의 워크트리를 생성하는 경우
상황
bash
[test@test-MacBookAir] ~/develop/project (feature/other-branch)❯ git worktree add /tmp/p-wt/feature-shared-harness feature/shared-harnessPreparing worktree (checking out 'feature/other-branch') fatal: 'feature/other-branch' is already used by worktree at '/Users/test/develop/project'
feature/other-branch로 체크아웃된 상태에서 해당 브랜치의 워크트리를 추가하려고함
명령어 내부의 새로 생기는 worktree 경로인 /tmp/p-wt/feature-shared-harness가 생성될 시 해당 경로의 브랜치는 feature/other-branch가 된다.
하지만 현재 경로의 브랜치도 feature/other-branch이기에 하나의 브랜치가 두개의 작업경로에 생성되게 된다.
이는 git의 기본 규칙 위반으로 실행이 실패하게된다.
해결
1. 현재 브랜치의 워크트리를 생성하려는 경우
git switch main 또는 git swtich {another-branch}를 통해 다른 브랜치로 이동 후 명령어를 재실행한다.