gitbutlerapp/gitbutler · error

not a git repository

Error message

not a git repository: {msg}

What it means

try_project() maps AddProjectOutcome::NotAGitRepository(msg) to this error, embedding the underlying discovery message. It means the path given as a project is not recognized as a git repository at all.

Solutions

  1. Run `git -C <path> status` to confirm the directory is a valid git repository.
  2. Correct the path passed to add-project (use the worktree root).
  3. Re-clone the repository if .git is missing or damaged.
  4. Check .git file permissions (readable by the user running the app).

Example fix

// before
add_project("~/Documents")                // not a repo
// after
add_project("~/Documents/my-app")        // directory containing .git
Defensive patterns

Strategy: validation

Validate before calling

const isRepo = (() => { try { execSync(`git -C ${path} rev-parse --git-dir`); return true; } catch { return false; } })();
if (!isRepo) throw new Error(`${path} is not a git repository`);

Type guard

const isGitRepo = (p) => { try { execSync(`git -C ${p} rev-parse --git-dir`, {stdio:'ignore'}); return true; } catch { return false; } };

Try / catch

if (let Err(e) = add_project(path) { if e.to_string().starts_with("not a git repository") { show_path_picker(); } }

Prevention

When it happens

Trigger: Calling try_project / add-project on a directory with no .git entry, an unreadable .git, or a malformed .git file pointer; path typos also land here depending on discovery.

Common situations: Adding the wrong folder after a refactor; .git deleted by a failed operation; case-sensitivity mismatches on macOS/Windows; passing a home directory instead of a repo.

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


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

Appendix: source

Thrown at crates/gitbutler-project/src/project.rs:337

            AddProjectOutcome::PathNotFound => Err(anyhow::anyhow!("project path not found")),
            AddProjectOutcome::NotADirectory => {
                Err(anyhow::anyhow!("project path is not a directory"))
            }
            AddProjectOutcome::BareRepository => {
                Err(anyhow::anyhow!("bare repositories are not supported"))
            }
            AddProjectOutcome::NonMainWorktree => {
                Err(anyhow::anyhow!("non-main worktrees are not supported"))
            }
            AddProjectOutcome::NoWorkdir => Err(anyhow::anyhow!("no workdir found for repository")),
            AddProjectOutcome::NoDotGitDirectory => {
                Err(anyhow::anyhow!("no .git directory found in repository"))
            }
            AddProjectOutcome::ReftableRefFormatUnsupported => Err(anyhow::anyhow!(
                "unsupported repository reference format: reftable"
            )),
            AddProjectOutcome::NotAGitRepository(msg) => {
                Err(anyhow::anyhow!("not a git repository: {msg}"))
            }
        }
    }
}

View on GitHub (pinned to 58e5313667)