gitbutlerapp/gitbutler · error

Repository has no workdir

Error message

Repository has no workdir

What it means

The teardown command shells out to the real `git checkout` binary, which requires a working directory to operate in. `git2::Repository::workdir()` returns `None` for bare repositories, so this error is thrown because a bare repo cannot have branches checked out.

Solutions

  1. Run `but teardown` from a non-bare clone that has a working tree.
  2. If the target is a bare repo, clone it to a working copy first and run teardown there.
  3. Verify repo configuration: `git rev-parse --is-bare-repository` should return false.

Example fix

// before
git clone --bare https://example.com/repo.git && cd repo.git && but teardown

// after
git clone https://example.com/repo.git && cd repo && but teardown
Defensive patterns

Strategy: validation

Validate before calling

let repo = ctx.repo.get()?;
if repo.is_bare() {
    anyhow::bail!("teardown requires a non-bare repository with a working tree");
}

Type guard

fn has_workdir(repo: &gix::Repository) -> bool { repo.workdir().is_some() }

Try / catch

match teardown(ctx, args) {
    Err(e) if e.to_string().contains("Repository has no workdir") =>
        eprintln!("Run this in a non-bare clone"),
    other => other?,
}

Prevention

When it happens

Trigger: Running `but teardown` (with a target branch to check out) inside a bare repository, or when the repository handle resolves to a bare repo object (e.g., pointing at `.git` directly).

Common situations: Executing the CLI with the repo root set to a bare clone (servers, CI check-out-less clones); misconfigured context where `ctx.repo.get()` yields a bare repository instead of a working tree.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at crates/but/src/command/legacy/teardown.rs:200

            }
        }
    }

    // Check out the target branch using Git directly
    if let Some(out) = out.for_human() {
        writeln!(
            out,
            "{}",
            t.hint
                .paint(format!("→ Checking out {target_branch_name}..."))
        )?;
    }

    // Use git checkout via command
    let repo = ctx.repo.get()?;
    let workdir = repo
        .workdir()
        .ok_or_else(|| anyhow::anyhow!("Repository has no workdir"))?;

    let output = std::process::Command::new(gix::path::env::exe_invocation())
        .arg("-C")
        .arg(workdir)
        .arg("checkout")
        .arg(&target_branch_name)
        .output()
        .context("Failed to execute git checkout")?;

    if !output.status.success() {
        // Checkout failed (likely due to local changes), try soft reset instead
        if let Some(out) = out.for_human() {
            writeln!(
                out,
                "  {}",
                t.attention.paint("⚠ Checkout failed, trying soft reset...\n  ⚠ This will leave changes from multiple branches in your working directory.\n  ⚠ You will have to manually remove, stash or re-commit the changes.")
            )?;
        }

View on GitHub (pinned to 58e5313667)