It's not actually creating a copy of the repository, it's putting a branch (or disconnected head) at specified path.
https://git-scm.com/docs/git-worktreeFrom any worktree or git clone directory:
git worktree list - will show current worktrees (identified by path) and the branch they are on
git worktree add ../<new worktree dir> <some branch that isn't being used> - will create a new worktree
Delete the folder when you are done.
git worktree prune - will update worktree list and remove tree branches that are no longer found.
So from my example, if I were in the head folder:
<drive/path to folder>/ProjectDirectory/head $ git worktree -b my_branch ../worktree1 origin/HEAD
will add a new folder called worktree under ProjectDirectory with a new branch called my_branch that is based off of origin/HEAD
There will be a .git file at ProjectDirectory/worktree1/.git that contains:
gitdir: <drive/path to folder>/ProjectDirectory/head/.git/worktrees/worktree1If you run "git rev-parse --show-toplevel" from that path, do you get the root from the copy or the original repository?
<drive/path to folder>/ProjectDirectory/worktree1 $ git rev-parse --show-toplevel
<drive/path to folder>/ProjectDirectory/worktree1