Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: swap the main working tree with a linked working tree?

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:

  • if <path> is a worktree, it swaps them
  • if <path> is a commit-ish, it adds a new worktree with <worktree>'s name for the commit-ish, then swaps them
like image 797
batch Avatar asked Nov 16 '22 01:11

batch


1 Answers

There is no automated way to move a main worktree, however, you can do it manually:

  • rename the main worktree, eg mv master main
  • edit the .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.

like image 88
Yves Dorfsman Avatar answered Dec 08 '22 01:12

Yves Dorfsman