The next step in my git worktree learning journey: syncing diverged branches.
I created a worktree for a feature while cleaning up my main branch history. After squashing/reordering commits, they diverged. How do I bring the cleaned-up changes into the worktree without affecting the main branch?
Lesson learned: the "thing" I am merging into is the branch, not the worktree. The worktree is merely a container for the second branch; a filesystem location where I may check out and work on another branch.
This means that the two branches may be synced using the same technique as if they were in the same workspace, typically using a merge or a rebase.
However, all the interactive rebasing I did on the main branch broke the parent-child relationship between the two branches. Therefore, rebasing is the more appropriate choice. I want to replay the feature commits on top of the cleaned-up branch so it's as if I wrote the feature on top of the cleaned-up branch to start with.
```bash
cd worktree
git checkout feature-branch
git rebase main-branch
```
#gitworktree #git #learning #TIL #devlife