Given I have run
$ git worktree add ~/worktrees/a
$ cd ~/worktrees/a
$ git status
On branch a
I would like to instead change the name of the worktree and branch from a to b.
One option for achieving this (that I ended up doing) is:
$ git worktree move ~/worktrees/a ~/worktrees/b
$ cd ~/worktrees/b
$ git branch -m b
Let's read the related command desc first.
git worktree move Move a worktree to a new location. Note that the main worktree or linked worktrees containing submodules cannot be moved with this command. (The git worktree repair command, however, can reestablish the connection with linked worktrees if you move the main worktree manually.)
Reference: https://git-scm.com/docs/git-worktree
For non-main worktree, just use git worktree move <worktree> <new-path>.
For main-worktree or worktree containing submodules, use mv <worktree> <new-path> to move the directory manually. Then enter the worktree, use git worktree repair to reestablish the connection with linked worktrees.
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