How do I use Graphite in a git worktree?
# how-do-i
b
How do I use Graphite in a git worktree?
➕ 2
✅ 1
p
(If applicable) To help us more clearly understand what you're trying to do, please provide additional details about: - Screenshots / debug logs / list of commands you've tried to run so far - Your workflow - Current state
f
I came here to ask the same question. I've tried to use multiple worktrees in the same Graphite stack and I ended up with a big mess
b
It might not be possible and honestly it might be two completely different approaches to the same problem. But thought I'd ask.
➕ 1
p
hey all, heres our doc on git worktrees.
gt
should work pretty seamlessly with worktrees as its operations are largely at the branch level. let me know if you're running into any issues.
b
Will do! Thanks.
f
@Josie Beaudoin Thanks, what I'm missing is how to keep the stack properly in sync across several worktrees. Let's say I create a worktree for a new PR in my stack. In my base repo, I will do some update and rebasing and my stack in the PR worktree might be out-of-sync. I guess ideally I should do Graphite operations only from the base repo, but the issue is that it's not possible to check out a branch opened in another worktree. So I end up doing a rebase in my PR worktree and I guess this is where is started to go wrong. Sorry I'm not super clear because I'm not quite sure what went wrong exactly but I do feel like it's error prone and once you start having diverging branches it's pretty much unrecoverable from a Graphite perspective
p
I guess ideally I should do Graphite operations only from the base repo, but the issue is that it's not possible to check out a branch opened in another worktree.
graphites stack metadata is sahred across all your worktrees so
gt
works the same from any of them. instead you can cd into the worktree and run your
gt
commands from there. for stack wide commands like
gt sync
and
gt restack
-- you'd want to run them from the worktree that owns the top of the stack.
So I end up doing a rebase in my PR worktree and I guess this is where is started to go wrong.
you wouldnt want to run
git rebase
but use
gt restack
instead as this will keep parent pointers and commit SHAs consistent within graphite.
f
Thanks I will give it another try today 👍