How do I get around this without deleting the .git/worktrees
directory?
You will have an easier time with Git 2.17+ (Q2 2018), since "git worktree
" has learned 'move
' and 'remove
' subcommands.
See commit 7f19def (04 Mar 2018) by Eric Sunshine (sunshineco
).
See commit ee6763a, commit cc73385, commit 78d986b, commit c64a8d2, commit 9f792bb, commit 9c620fc (12 Feb 2018), and commit 4ddddc1 (24 Jan 2018) by Nguyễn Thái Ngọc Duy (pclouds
).
(Merged by Junio C Hamano -- gitster
-- in commit bd0f794, 14 Mar 2018)
In your case, you could move the existing worktree to the place you now wants it (when attempting to create a new worktree for the same branch).
worktree move
: new command
This command allows to relocate linked worktrees.
Main worktree cannot (yet) be moved.
And:
worktree move
: refuse to move worktrees with submodules
Submodules contains .git
files with relative paths.
After a worktree move
, these files need to be updated, or they may point to nowhere.
This is a bandage patch to make sure "worktree move
" don't break people's worktrees by accident.
When .git
file update code is in place, this validate_no_submodules()
could be removed.
Note: before Git 2.21 (Q1 2019), "git worktree remove
" and "git worktree move
" refused to work when there is a submodule involved.
This has been loosened to ignore uninitialized submodules.
With Git 2.43 (Q4 2023), a message written in olden time prevented a branch from getting checked out saying it is already checked out elsewhere, but these days, we treat a branch that is being bisected or rebased just like a branch that is checked out and protect it.
Rephrase the message to say that the branch is in use.
See commit 2a49926, commit 92edf61 (07 Aug 2023) by Rubén Justo (rjusto
).
(Merged by Junio C Hamano -- gitster
-- in commit f5f23a4, 24 Aug 2023)
branch
: error message checking out a branch in use
Signed-off-by: Rubén Justo
Let's update the error message we show when the user tries to check out a branch which is being used in another worktree, following the guideline reasoned in 4970bed ("branch
: update the message to refuse touching a branch in-use", 2023-07-21, Git v2.42.0-rc0 -- merge).
Instead of is already checked out at
, you will see is already used by worktree at
.
This follows up Git 2.42 change.
git worktree move
can be of interest (with Git 2.17+, Q2 2018): see my answer below. – Nitid