← Back to context

Comment by matheusmoreira

13 hours ago

Git worktrees won't allow me to check out a branch twice though. I wonder if there's some technical limitation that prevents it.

That is, because the metadata is shared between worktrees. So you when you modify a branch in one worktree, it isn't modified per worktree, but in the whole repo. So what you need to do is to duplicate the branch metadata. That's what git clone does. You essentially have these cases:

    shared worktree, shared branch/index data, shared object storage  -> single repo, single worktree
    separate worktree, shared branch/index data, shared object storage  -> repo, with worktrees
    separate worktree, separate branch/index data, shared object storage  -> git clone
    separate worktree, separate branch/index data, separate object storage  -> git clone --no-hardlinks

You can checkout a commit twice though. What I don't get is what checking out a branch twice gets you. As soon as you add a single commit, these branches will be different, so why not just create another branch? Branches in git are cheap.