Expecting that you are inside your repository you want to add a worktree for, you can just call this script. git rev-parse --show-toplevel
will ensure that the new worktree is created as sibling of your repository.
It will create worktrees for all the given branches as siblings to your repository root folder. Instead of specifying an array of branches, you may just specify a string at the beginning.
A proposed local folder structure is as follows:
github/user/repository/branch
where you typically start with
github/user/repository/master
and then add a worktree like
github/user/repository/bug-2
-
Your current directory is within the repository you want to create a worktree for.
-
The branch you want to create the worktree for is already available at remote.
So this one is especially meant to create worktrees for development, maintenance and release branches.