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