gitbutlerapp/gitbutler · error

The repository at has no working directory. GitButler…

Error message

The repository at {} has no working directory. GitButler requires a working directory.

What it means

Thrown when `AddProjectOutcome::NoWorkdir` is returned. The repository resolves but `git` reports no working directory (core.bare semantics or an unusual setup), so GitButler cannot manage files in the working tree.

Solutions

  1. Check `git config core.bare` in the repo; set it to false if wrongly enabled: `git config core.bare false`.
  2. Re-clone the repository to restore a healthy working directory.
  3. Verify `git rev-parse --show-toplevel` returns a path before running setup.

Example fix

// before
core.bare = true
// after
git config core.bare false
Defensive patterns

Strategy: validation

Validate before calling

const bare = await run(['git', '-C', repoPath, 'config', '--get', 'core.bare']);
const toplevel = await run(['git', '-C', repoPath, 'rev-parse', '--show-toplevel']);
if (bare.trim() === 'true' || !toplevel.trim()) {
  throw new Error(`${repoPath} has no working directory`);
}

Type guard

function hasWorkdir(p: string): boolean {
  const r = cp.spawnSync('git', ['-C', p, 'rev-parse', '--show-toplevel']);
  return r.status === 0 && r.stdout.toString().trim().length > 0;
}

Try / catch

try {
  await run(['but', 'setup', repoPath]);
} catch (e) {
  if (String(e).includes('no working directory')) {
    console.error('Check core.bare and re-clone if the checkout is broken.');
  }
  throw e;
}

Prevention

When it happens

Trigger: Running setup on a repo whose working directory cannot be resolved (e.g. `core.bare = true` set on a non-bare-looking repo, or a stripped checkout).

Common situations: Manually toggling `core.bare` in `.git/config`; broken or partially deleted checkouts; repos migrated by tools that dropped the worktree config.

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/0db6cb19216358fd. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/command/legacy/setup.rs:269

            Ok(ProjectStatus::AlreadyExists)
        }
        gitbutler_project::AddProjectOutcome::PathNotFound => Err(anyhow::anyhow!(
            "The path {} does not exist",
            repo_path.display()
        )),
        gitbutler_project::AddProjectOutcome::NotADirectory => Err(anyhow::anyhow!(
            "The path {} is not a directory",
            repo_path.display()
        )),
        gitbutler_project::AddProjectOutcome::BareRepository => Err(anyhow::anyhow!(
            "The repository at {} is bare. GitButler requires a non-bare repository.",
            repo_path.display()
        )),
        gitbutler_project::AddProjectOutcome::NonMainWorktree => Err(anyhow::anyhow!(
            "The repository at {} is a non-main worktree. GitButler requires the main worktree.",
            repo_path.display()
        )),
        gitbutler_project::AddProjectOutcome::NoWorkdir => Err(anyhow::anyhow!(
            "The repository at {} has no working directory. GitButler requires a working directory.",
            repo_path.display()
        )),
        gitbutler_project::AddProjectOutcome::NoDotGitDirectory => Err(anyhow::anyhow!(
            "The repository at {} has no .git directory. GitButler requires a .git directory.",
            repo_path.display()
        )),
        gitbutler_project::AddProjectOutcome::ReftableRefFormatUnsupported => Err(anyhow::anyhow!(
            "The repository at {} uses the currently unsupported reftable reference format.",
            repo_path.display()
        )),
        gitbutler_project::AddProjectOutcome::NotAGitRepository(_) => Err(anyhow::anyhow!(
            "The path {} is not a git repository.",
            repo_path.display()
        )),
    }?;

    // A ported project can keep its target in Git config while the legacy `virtual_branches.toml`

View on GitHub (pinned to 58e5313667)