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

Bug: git worktree remove and overwritten directory

From
Jonathan Müller <jonathanmueller.dev@gmail.com>
Date
May 20, 2020, 10:36 UTC
Message-ID
<89526b3a-297d-591d-6e12-48580d697ed5@gmail.com>
Apologies, if this has already been reported.

It seems to be impossible to remove a git worktree whose location has been replaced by the main working tree (don't ask how I found out). Steps to reproduce:

``` git init test cd test git commit --allow-empty -m"Initial commit" git branch some-branch git worktree add ../test2 some-branch cd ../ rm -rf test2 # Remove the worktree folder mv test test2 # Main git repository now located where the worktree used to be ```

Afterwards, `git worktree list` reports:

/home/foonathan/test2 e7bb748 [master] /home/foonathan/test2 e7bb748 [some-branch]

And both `git worktree remove .` and `git worktree remove ../test2` report an error `fatal: '../test2' is a main working tree`. I had to manually remove the corresponding folder from `.git/worktree` to get rid of it. The issue is especially annoying, because you can't check out `some-branch` anymore (as it's already checked out in the worktree).

I've tested it with git version 2.26.2 and also the version currently on the next branch.

Thank you, Jonathan

Next: Shourya Shukla
Message 1 of 6 in “Bug: git worktree remove and overwritten directory”
  1. Jonathan MüllerMay 20, 2020
  2. Shourya ShuklaMay 20, 2020
  3. Eric SunshineMay 20, 2020
  4. Jonathan MüllerMay 20, 2020
  5. Eric SunshineJun 8, 2020
  6. Jonathan MüllerJun 8, 2020

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.