1

I have a repo with 2 banch: master and b1.

Currently, the checkout branch is master (in main worktree).

I create a worktree (called b1_worktree) and checkout the b1 branch by default.

So now I can work on both branch without using "checkout" command.

And this is my questions:

  • After changing the code in branch b1 in b1_worktree, how can I merged b1 from b1_worktree to master branch in main worktree?
  • And is it possible to update the b1 content from b1_worktree to main worktree?

2 Answers2

1

To git, once you commit something on b1_worktree, it will move b1 branch, which will be visible on the original worktree. So just merge b1 there and the change should magically work.

Pang
  • 9,564
  • 146
  • 81
  • 122
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • I tried committing something on b1_worktree. After delete the b1_worktree, the commit of the b1_branch in b1_worktree is "automatically" update to original worktree. What should I do if I want to update commit of b1 from b1_worktree to original worktree manually? Thank you in advance. – Linh Truc Vo Sep 23 '21 at 18:24
  • I read the comment from @Romain Now I understand the root. Thank you both. – Linh Truc Vo Sep 23 '21 at 18:27
0

If need to merge from worktree HEAD (e.g. in detach mode), then please see https://git-scm.com/docs/git-worktree#_refs

Refs that are per-worktree can still be accessed from another worktree via two special paths, main-worktree and worktrees. The former gives access to per-worktree refs of the main worktree, while the latter to all linked worktrees.

For example, main-worktree/HEAD or main-worktree/refs/bisect/good resolve to the same value as the main worktree’s HEAD and refs/bisect/good respectively. Similarly, worktrees/foo/HEAD or worktrees/bar/refs/bisect/bad are the same as $GIT_COMMON_DIR/worktrees/foo/HEAD and $GIT_COMMON_DIR/worktrees/bar/refs/bisect/bad.

Boaz Nahum
  • 1,049
  • 8
  • 9