0

I have a branch feature/issue/xyz on github and when I try to checkout via git-worktee it keeps telling me does not exist

hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.

I know it exists , verified bot on github & in a non worktree clone locally I have tried : git worktree add --track -b feature/issue/xyz feature/issue/xyz origin/feature/issue/xyz

git worktree add --track -b feature/issue/xyz feature/issue/xyz origin/feature/issue/xyz

and git worktree add --track -b feature/issue/xyz feature/issue/xyz refs/heads/feature/issue/xyz

I have tried git fetching but all I see is

 * branch              HEAD       -> FETCH_HEAD

and still get the same result after I try to add again

jonnie
  • 12,260
  • 16
  • 54
  • 91
  • You have a *single-branch clone*. You need to "undo" its single-branch-ness. (It's not clear to me how you're supposed to know that you have this, other than if you remember running `git clone --single-branch` or `git clone --depth` whenever you ran `git clone` originally. But that's the problem.) – torek Dec 21 '21 at 20:20
  • unless I am misunderstanding you, this is not a single branch clone, its a bare clone to work with git worktree `git clone --bare ...` – jonnie Dec 22 '21 at 16:41
  • It may or may not be bare, but it's apparently *also* a single-branch clone, based on the `git fetch` result. – torek Dec 22 '21 at 19:41

1 Answers1

3

I solved this by:

git fetch origin 'refs/heads/*:refs/heads/*'

and then simply add git worktree add feature/issue/xyz feature/issue/xyz and this pulled the correct branch

jonnie
  • 12,260
  • 16
  • 54
  • 91
  • This "works", but it's not the same as actually branching from `origin/feature/issue/xyz` directly - fetching all remote branches first is slow and needs to be re-run every time you want to reference the remote's state. By contrast branching from `origin/...` is automatically in-sync with the commits on the remote without needing to fetch all branches. – dimo414 Aug 22 '23 at 18:22