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

Bug with worktrees...

From
John Szakmeister <john@szakmeister.net>
Date
Aug 27, 2015, 19:03 UTC
Message-ID
<CAEBDL5UQSvS=t1dUKYqK6R=xHU6RU3bS72w-i02ey-Y_VB9KMQ@mail.gmail.com>

My apologies if this has already been reported, but I ran into an interesting bug with worktrees. In particular, I have an alias 'st' that maps to 'status -sb'. When running this under a subdirectory of a worktree created with 'git worktree add', it fails complaining that the work tree has already been set.

Here's a script to reproduce the problem:
    git init test-repo
    cd test-repo
    git config --local alias.st 'status -sb'
    mkdir subdir
    echo file > subdir/file.txt
    git add subdir/file.txt
    git commit -m 'add file'
    git branch foo
    git worktree add ../new-worktree foo
    cd ../new-worktree/subdir
    echo "new line" >> file.txt
    echo "this will work"
    git status -sb
    echo "this fails"
    git st
When I run it, I see this:
Initialized empty Git repository in
/home/jszakmeister/tmp/test-case/test-repo/.git/
[master (root-commit) 1ec5360] add file
 1 file changed, 1 insertion(+)
 create mode 100644 subdir/file.txt
Enter ../new-worktree (identifier new-worktree)
Switched to branch 'foo'
this will work
## foo
this fails
fatal: internal error: work tree has already been set
Current worktree: /home/jszakmeister/tmp/test-case/new-worktree
New worktree: /home/jszakmeister/tmp/test-case/new-worktree/subdir
Hope this helps!
-John
Next: Eric Sunshine
Message 1 of 3 in “Bug with worktrees...”
  1. John SzakmeisterAug 27, 2015
  2. Eric SunshineAug 28, 2015
  3. John SzakmeisterAug 28, 2015

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.