I'm trying to find out if there's any way to swap working trees. My company has a lot of scripts that assume a specific directory structure, so to be able to work with multiple working trees, I would need the "new" linked worktree to take the place of the main worktree.
I found git worktree move <worktree> <new-path>
but that doesn't allow "main" working trees to be moved, so there's no chance of swapping.
Ideally, there would be a git worktree swap <worktree> <path>
where:
<path>
is a worktree, it swaps them<path>
is a commit-ish, it adds a new worktree with <worktree>
's name for the commit-ish, then swaps themThere is no automated way to move a main worktree, however, you can do it manually:
mv master main
.git
files in every link worktree to reflect that change, eg: sed -i 's!/master/!/main/!' .git
.git
is a directory in the main worktree, but just a text file containing the path to the main worktree in the link worktree, which you can edit with your favourite editor.
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