I've been experimenting with git worktree and found some weird issue. Maybe it has to do cloning the repository as --bare.
$ cd ~
$ git clone --bare https://github.com/actions/checkout.git
The checkout repository has a remote called origin:
$ git remote -v
origin https://github.com/actions/checkout.git (fetch)
origin https://github.com/actions/checkout.git (push)
In upstream projects I usually have multiple remotes and I like to look at the logs of each remote by doing git log origin/main for example.
Let's do that in the bare repository:
$ cd ~/checkout.git
$ git log origin/main
fatal: ambiguous argument 'origin/main': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Why is that?
Even when I create a worktree for a hotfix I get the same error:
$ cd ~/checkout.git
$ git worktree add -b hotfix ~/checkout.git/hotfix main
$ cd ~/checkout.git/hotfix
$ git log origin/main
fatal: ambiguous argument 'origin/main': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Adding the -- separator from the help also doesn't help:
$ git log origin/main --
fatal: bad revision 'origin/main'
Thank you @matt for you comments. They were helpful.
I don't know if this is the way one is supposed to be using worktrees but if I want to create a worktree for a hotfix based on
origin/mainand use the really remote branch notationorigin/mainI can do it like this.This is solving my problem.