git worktree is a command that allows you to work with two or more branches at the same time.
With the command git worktree add you can create a new directory with the same repository as the current one, but with a different branch.
For example, create a copy of this repository in the branch fix/quick-fix in the ../go-study-2 directory and with origin/main branch as source:
git worktree add -b fix/quick-fix ../go-study-2 origin/main
# Alternatively, you can create a new work tree without creating a new branch
git worktree add ../go-study-2 origin/main
Now, if you go to the ../go-study-2 directory you can work in the new branch:
cd ../go-study-2 && code .
The git worktree list command list all worktrees related to the current repository:
git worktree list
The git worktree remove command remove a worktree:
git worktree remove go-study-2
👉 Source