gitbutlerapp/gitbutler · error
The path is not a git repository.
Error message
The path {} is not a git repository. What it means
Thrown when `AddProjectOutcome::NotAGitRepository(_)` is returned. After all other checks, the path was determined not to be a git repository; the wrapped inner error carries git's own diagnostic. This is the terminal fallback of the AddProjectOutcome match in setup.
Solutions
- Run `git -C <path> status` to confirm git itself recognizes the repo.
- If not a repo, either `git init` (new project) or clone the correct URL.
- If `.git` is corrupted, re-clone the repository from the remote.
Example fix
// before but setup ~/empty-folder // after git init ~/empty-folder # or clone the repo but setup ~/empty-folder
Defensive patterns
Strategy: validation
Validate before calling
const st = cp.spawnSync('git', ['-C', repoPath, 'status', '--porcelain']);
if (st.status !== 0) {
throw new Error(`${repoPath} is not a valid git repository: ${st.stderr}`);
} Type guard
function isGitRepo(p: string): boolean {
return cp.spawnSync('git', ['-C', p, 'rev-parse', '--git-dir']).status === 0;
} Try / catch
try {
await run(['but', 'setup', repoPath]);
} catch (e) {
if (String(e).includes('is not a git repository')) {
console.error('git init or clone the project before running but setup.');
}
throw e;
} Prevention
- Run `git status` as a preflight in scripts wrapping but setup.
- Verify you are in the right directory before onboarding.
- If git commands fail with corruption errors, re-clone before setup.
When it happens
Trigger: Running `but setup` on a non-repo directory (no `.git`, not detected by gix), or a corrupted `.git` that fails to open.
Common situations: Wrong directory selected in setup; empty newly created folder; `.git` corrupted by interrupted operations or disk issues.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- `but setup` cannot run from a linked worktree; run it from…
- No git repository found at
- No git repository found - run `but setup --init` to…
- No HEAD reference found for remote
- Repository has no working directory
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/1bf9c2c77b11e126.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/setup.rs:281
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 58e5313667)