Clone or create a new project using gitwt.
It uses a "bare repository" strategy. This way, there's a clear root for the project and there's no need to clone everything - new worktrees only duplicate code, git database stuff remains in a single place.
From the root of the project:
git fetch origin
git worktree add -b <branch-name> <branch-dir> [<base-branch>] # `main` by default
cd <branch-dir>(work commit push review merge)
git worktree remove <branch-name>NOTE: remove can fail to delete the worktree dir if an editor is still open. In this case, the branch is deleted, but the physical folder remains
From the root of the project:
git fetch origin
git worktree add <branch-dir> <branch-name>
cd <branch-dir>(work commit push review merge)
git worktree remove <branch-name>Git tries to resolve it in this order:
- Local branch exists → checks it out in the new worktree
- Local branch doesn't exist, but a matching remote-tracking branch does → automatically creates a local branch tracking the remote one (same as git checkout feature-branch when origin/feature-branch exists)
- Neither exists → error