gitbutlerapp/gitbutler · error

Visible worktree was listed more than once

Error message

Visible worktree {name} was listed more than once

What it means

Visible worktrees are keyed by name in a map of checkouts; duplicates would make checkout identity ambiguous during materialization. If the worktree list yields the same name twice, creation of the rebase editor aborts rather than silently picking one.

Solutions

  1. Run `git worktree prune` to clean stale worktree metadata, then retry
  2. Inspect .git/worktrees/ for duplicate admin directories and remove the invalid one
  3. Ensure worktrees have unique names when creating them (`git worktree add <unique-path>`)

Example fix

// before: creating worktrees with colliding names
git worktree add ../repo feature && git worktree add ../repo2 feature
// after: unique branch per worktree
git worktree add ../repo feature-a && git worktree add ../repo2 feature-b
Defensive patterns

Strategy: validation

Validate before calling

let mut names = std::collections::HashSet::new();
for wt in visible_worktrees {
    anyhow::ensure!(names.insert(wt.name.clone()), "duplicate worktree name: {}", wt.name);
}

Try / catch

match create_with_opts(&workspace, &tips, opts) {
    Ok(ed) => ed,
    Err(e) if e.to_string().contains("listed more than once") => {
        run_git(&repo, ["worktree", "prune"])?;
        let ws = but_workspace::refresh(&repo)?;
        create_with_opts(&ws, &tips, opts)?
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `create_with_opts` when the underlying worktree enumeration returns two visible worktrees with identical names — typically a corrupted .git/worktrees metadata directory or two proxy entries sharing a name.

Common situations: Manually copied or hand-edited .git/worktrees directories; leftover worktree admin dirs after a crash; filesystem case-insensitivity causing name collisions; buggy external tooling duplicating worktree entries.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/f0eff93c3dd0f236. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-rebase/src/graph_rebase/creation.rs:354

                    format!(
                        "Visible detached worktree {} HEAD {} is missing from the editor",
                        tip.name, tip.id
                    )
                })?,
            };
            let name = tip.name.clone();
            let checkout = Checkout::Worktree {
                worktree_name: name.clone(),
                selector: Selector {
                    id: selector,
                    revision: 0,
                },
                ref_name: tip.ref_name,
                initial_head: tip.id,
                merge_base_override: None,
            };
            if worktree_checkouts.insert(name.clone(), checkout).is_some() {
                bail!("Visible worktree {name} was listed more than once");
            }
        }

        let checkouts = worktree_checkouts
            .into_values()
            .chain(head_selectors.into_iter().map(|selector| Checkout::Head {
                selector,
                merge_base_override: None,
            }))
            .collect();

        Ok(Self {
            graph,
            initial_references: references,
            checkouts,
            repo: repo.clone().with_object_memory(),
            history: RevisionHistory::new(),
            workspace,

View on GitHub (pinned to 58e5313667)