How can I fetch a branch from a repository but checkout to a new worktree?
Something like:
> git fetch origin releases/gcc-13
From git://gcc.gnu.org/git/gcc
* branch releases/gcc-13 -> FETCH_HEAD
> git worktree add ../gcc-13 releases/gcc-13
fatal: invalid reference: releases/gcc-13
What I do not want is to checkout that branch to the current working directory (where .git is located) but to a new folder ../gcc-13.
git branch does not show releases/gcc-13. AFAIU I'd have to do something like
> git checkout --track origin/releases/gcc-13
but that would checkout gcc-13 to the current path, which is not what I want.
As you can see in this line:
git fetchdidn't store the downloaded branch (namedreleases/gcc-13on the remote side) to a "regular" tracking branch on the local side, but to the pseudo-refFETCH_HEAD. This happened because you gave an explicit branch name on thegit fetchcommand:The next thing you should do is provide a branch name for the downloaded commits:
Now you can check out the branch in its own worktree.
Notable things:
git branchis at this point completely unrelated to the remote branch of the same name. They just happen to be the same name and point to the same commit at this time.