Skip to content

traverse cannot work with branches already checked out in worktrees #1522

@lsierant

Description

@lsierant

git traverse -W refuses to continue when a managed branch is already checked out in another location using git worktree:

fatal: 'feature-branch' is already checked out at 'path/to/the/worktree/'
git checkout --quiet feature-branch -- returned 128

When working with stacked PRs or generally multiple PRs (otherwise why would you need git machete in the first place!) it's actually very common to have them checked out in separate worktrees. So this is entirely blocking using traverse when worktrees are involved.

Am I missing something?

I have two ideas how to solve this:

  1. Quick and potentially unsafe: add the option to traverse with --ignore-other-worktrees added to git checkout operations. The problem is when the worktrees are in a dirty state. This wouldn't update the state in the worktree itself and might leave an inconsistent state of the branch. Perhaps, only in case of dirty state traverse would refuse to work.
  2. Instead of checking out, traverse could jump cd into the worktree and perform the necessary updates from there.

Metadata

Metadata

Assignees

Labels

traverseRelates to how tree traversal is performed

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions