Thread (4 messages) flat view 4 messages, 2 authors, 2016-06-15

git worktree fails to recreate existing branch even with -B

From: Kirill Likhodedov <hidden>
Date: 2016-06-15 23:08:10

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help