1

I want to move my current git branch to different git worktree b/c I want to modify the read/write file permissions without effecting the file permissions of the other branches in the current worktree.

How can I move/copy my current branch to a different worktree and how can I get back to the original worktree?

3 Answers3

3

I "move" a branch to my alternate worktree like this

  1. Checkout any other branch in my current tree. (the branch you want to move can not be checked out)
  2. Open a git window in my alternate worktree and checkout the branch I want to "move"

That is all. I have two git windows open side by side. (my main worktree and my alternate) Its real easy to see what I'm doing.

VonC posted a great resource Multiple working tree directories

hlovdal
  • 26,565
  • 10
  • 94
  • 165
0

Try with this

  • copy current working directory
  • checkout destination branch
  • paste
  • commit

or with ...

  • git checkout branch that you want to move
  • git rebase destination branch

in case of conflict, if you want to manage them :

  • git checkout branch that you want to move
  • git rebase -i destination branch
sensorario
  • 20,262
  • 30
  • 97
  • 159
0

You don't need to and cannot "copy" branch because branches are shared between worktrees, it is there already. Probably what you meant is to checkout current branch on a different worktree. That is possible by 2 ways:

  • temporary checkout current woktree to a different branch: git checkout -b tmp (I'm not sure how it behaves when you have uncommitted changes), then checkout that branch in another worktree, or
  • use another temporary branch based on the current. It would originally be the same commit which should be enough in most cases.
max630
  • 8,762
  • 3
  • 30
  • 55