I'm attempting to add a worktree to a remote branch, if the branch isn't stored locally.
I can successfully do this and get all the files using the following command:
git worktree add issue origin/issue
Which produces the following output:
Preparing issue (identifier issue)
HEAD is now at d4bb4b9 Action edit performed on issue: ISSUE-1
This makes it seem as if the worktree was successful. If I look at the files, everything is there.
However, the git status command looks like this
git status
Not currently on any branch.
nothing to commit, working tree clean
and I can't push/pull anything. Git version is 2.14.1 btw on windows (if it makes a difference)
Does anyone know how to fix this? If the branch is local and you remove the origin/, it works perfectly fine. It's just dealing with the remote that it seems to not agree with.
The full syntax is:
git worktree add [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<commit-ish>]
So try:
git worktree add --checkout -b issue ../a/path origin/issue
The OP Liam Kelly adds in the comments:
However you don't actually need the
--checkout
for the command, using-b
is all you need.
I didn't even think about-b
being able to create the branch locally from a remote.