git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

Next: Duy Nguyen
Message 1 of 6 in “git worktree fails to recreate existing branch even with -B”
  1. Kirill LikhodedovFeb 9, 2016
  2. Duy NguyenFeb 15, 2016
  3. 1/2 worktree: fix "add -B"Nguyễn Thái Ngọc Duy, Feb 15, 2016
  4. 2/2 worktree add -B: do the checkout test before update branchNguyễn Thái Ngọc Duy, Feb 15, 2016
  5. Junio C HamanoFeb 15, 2016
  6. Duy NguyenFeb 16, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.