I started using git worktrees. It seems to work, but I'm getting this error when attempting to check out a branch in the cloned worktree:
fatal: '<branch>' is already checked out at '</other/location>'
How do I get around this without deleting the .git/worktrees
directory?
To remove a locked worktree, specify --force twice. With add , create a new branch named <new-branch> starting at <commit-ish> , and check out <new-branch> into the new worktree. If <commit-ish> is omitted, it defaults to HEAD . By default, -b refuses to create a new branch if it already exists.
A Git worktree is a linked copy of your Git repository, allowing you to have multiple branches checked out at a time. A worktree has a separate path from your main working copy, but it can be in a different state and on a different branch.
The working tree is the set of all files and folders a developer can add, edit, rename and delete during application development. The status command can provide insight into how the Git working tree behaves. More colloquially, developers often refer to the Git working tree as the workspace or the working directory.
Git won't let you check out the same branch twice, because if you do, and then go to one of the two work-trees and make a new commit, you'll set yourself up for misery when you go back to the other work-tree.
If you have actually removed the other work-tree, simply run git worktree prune
to make Git realize this. If you have not actually removed the other work-tree, don't check it out twice: it's no fun.
If you search for "worktree" in the manual git-checkout(1)
you'll find
git checkout --ignore-other-worktrees <branch>
But you probably just want to do the following so when you move (commit to) the branch in one worktree, the HEAD of the other worktree is not moved.
git checkout --detach <branch>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With