gitbutlerapp/gitbutler · error

The path {} is not a git repository.

Error message

The path {} is not a git repository.

What it means

Raised while registering a repository: the directory exists and has some git-looking structure, but `gitbutler_project` concluded it is not a git repository (`AddProjectOutcome::NotAGitRepository`). This is the catch-all git-detection failure after the more specific checks (missing .git, bare, worktree, reftable) did not match.

Source

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

            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`
    // / database store is empty — for example after that store was reset. The check below would
    // then see a target and report "already set up", but the workspace needs the legacy default
    // target to work. Repair it from the workspace first so setup isn't a dead end.
    if gitbutler_branch_actions::base::bootstrap_default_target_if_missing(&*ctx)?
        && let Some(out) = out.for_human()
    {
        writeln!(
            out,
            "  {}",
            t.success.paint("✓ Repaired missing target metadata")
        )?;
    }

View on GitHub (pinned to caf1f223d3)

Solutions

  1. Sanity-check with git itself: `git -C /the/path status` — whatever error it reports is the root cause
  2. If discovery is blocked by ownership, allow it: `git config --global --add safe.directory /the/path`
  3. If `.git` is corrupt or partial, re-clone the repository
  4. Make sure you point at the actual repo root, not a parent or unrelated subfolder

Example fix

# before: path passes directory checks but git itself is broken
git -C ~/work/project status   # reports 'not a git repository' or dubious ownership

# after: fix discovery, then register
git config --global --add safe.directory ~/work/project
but setup ~/work/project
Defensive patterns

Strategy: validation

Validate before calling

if gix::discover(&repo_path).is_err() {
    anyhow::bail!("git itself cannot open {repo_path:?}; run 'git -C {repo_path:?} status' to see why");
}

Type guard

fn is_not_a_repo(out: &gitbutler_project::AddProjectOutcome) -> bool {
    matches!(out, gitbutler_project::AddProjectOutcome::NotAGitRepository(_))
}

Try / catch

match add_project(&repo_path) {
    Ok(out) if is_not_a_repo(&out) => { /* surface git's own error for the path */ }
    Ok(out) => { /* other outcomes */ }
    Err(err) if err.to_string().contains("not a git repository") => { /* repo-repair guidance */ }
    Err(err) => return Err(err),
}

Prevention

When it happens

Trigger: Setup against a directory with a corrupted or foreign `.git` (truncated copy, wrong ownership/permissions so discovery fails, a `.git` file with a dangling worktree pointer), or a directory containing only nested content that is not itself a repo root.

Common situations: Interrupted clones or rsyncs; `.git` contents made unreadable (permission/ownership changes, safe.directory issues); tools that write their own `.git`-named files; wrong nesting level when pointing at a parent folder.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/1bf9c2c77b11e126. Report an issue: GitHub.