git worktree fails to recreate existing branch even with -B
- From
Kirill Likhodedov <kirill.likhodedov@jetbrains.com>
- Date
- Feb 9, 2016, 14:54 UTC
- Message-ID
- <344AE670-BF9A-4779-AFB0-50B870E1D488@jetbrains.com>
Git doesn’t allow me to execute
git worktree add -B <branch> <path> <start-point>
where <branch> already exists in the repository.The command prints the following:
Preparing <path> (identifier <branch>)
fatal: Refusing to point HEAD outside of refs/I’m trying to create a worktree on an existing branch <branch>, which should point to <start-point>. This obviously should fail with “-b”, but I use “-B” and expect it to be reset to <start-point> as mentioned in the docs:
By default, -b refuses to create a new branch if it already exists.
-B overrides this safeguard, resetting <new-branch> to <branch>.Do I miss something or there is a bug?
Steps to reproduce:
git init wt cd wt echo 'asd' > a.txt ; git add a.txt ; git commit -m initial git branch br1 git worktree add -B br1 ~/temp/br1 master
Error message: Preparing /Users/loki/temp/br1 (identifier br1) fatal: Refusing to point HEAD outside of refs/
Thanks a lot! -- Kirill