zed-industries/zed · error

git worktree list failed: {stderr}

Error message

git worktree list failed: {stderr}

What it means

Enumerates linked worktrees via `git worktree list --porcelain`; a non-zero exit surfaces git's stderr. Causes are in the stderr text: unreadable or broken worktree metadata, a dangling `.git` file in a linked worktree, unsupported git version, or repository ownership/permission failures.

Source

Thrown at crates/git/src/repository.rs:2154

                }
            })
            .boxed()
    }

    fn branches(&self) -> BoxFuture<'_, Result<BranchesScanResult>> {
        let git = self.git_binary();
        self.executor
            .spawn(async move {
                let fields = [
                    "%(HEAD)",
                    "%(objectname)",
                    "%(parent)",
                    "%(refname)",
                    "%(upstream)",
                    "%(upstream:track)",
                    "%(committerdate:unix)",
                    "%(authorname)",
                    "%(contents:subject)",
                ]
                .join("%00");
                let args = vec![
                    "for-each-ref",
                    "refs/heads/**/*",
                    "refs/remotes/**/*",
                    "--format",
                    &fields,
                ];
                let output = git.build_command(&args).output().await?;

                let error = if output.status.success() {
                    None
                } else {
                    let error = format_branch_scan_error(&output);
                    log::warn!("failed to get git branches with commit metadata: {error}");
                    Some(error.into())
                };

View on GitHub (pinned to 5a9b9558db)

Solutions

  1. Prune stale worktree metadata: `git worktree prune`, then retry.
  2. Re-register or remove broken linked worktrees (`git worktree remove <path>` or delete the dangling `.git/worktrees/<id>` entry).
  3. Confirm git is >= 2.7 so the porcelain listing exists.
  4. Fix safe.directory/permission issues reported in the appended stderr.
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = repo.worktrees(..).await {
    if e.to_string().contains("worktree list failed") {
        // suggest: git worktree prune; verify git >= 2.7; check safe.directory
    }
    return Err(e);
}

Prevention

When it happens

Trigger: A linked worktree whose `.git` file points to a moved or deleted main repository (`fatal: not a git repository`); corrupt `.git/worktrees/<id>` metadata after moving/deleting worktrees on disk without `git worktree prune`; git older than 2.7 lacking `worktree list --porcelain`; dubious-ownership failures.

Common situations: Worktrees relocated or removed with rm instead of `git worktree remove`; main checkout moved while linked worktrees remained; repos copied between machines or restored from backups with stale administrative worktree files.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of zed-industries/zed@5a9b9558db (2026-08-20). Data as JSON: /api/errors/91918d589002ab1b. Report an issue: GitHub.