gitbutlerapp/gitbutler · error
no .git directory found in repository
Error message
no .git directory found in repository
What it means
gitbutler-project's try_project() validates a directory before adding it as a project. If the repository discovery (AddProjectOutcome::NoDotGitDirectory) finds no .git directory, the project cannot be tracked, so this anyhow error is returned. GitButler requires the repo to have a .git directory to store its metadata.
Solutions
- Verify the directory is a proper non-bare git checkout (a .git entry exists and is a directory).
- Re-clone the repository if .git is missing or corrupted.
- If using a linked worktree, open the main worktree instead — non-main worktrees are separately rejected.
- Ensure the path passed to add-project is the worktree root, not a subdirectory or the .git folder itself.
Example fix
// before
add_project("/srv/myrepo.git") // bare repo, no .git dir
// after
git clone /srv/myrepo.git ~/work/myrepo
add_project("~/work/myrepo") // non-bare checkout with .git Defensive patterns
Strategy: validation
Validate before calling
const path = '/srv/myrepo';
if (!fs.existsSync(pathJoin(path, '.git'))) {
throw new Error(`${path} has no .git directory; cannot add as project`);
} Type guard
const isGitCheckout = (p) => fs.existsSync(pathJoin(p, '.git')) && fs.statSync(pathJoin(p, '.git')).isDirectory();
Prevention
- Only add non-bare checkouts as projects.
- Check for .git existence before programmatic project creation.
- Avoid operating on linked worktrees with GitButler.
When it happens
Trigger: Calling try_project (or the project-add API path that calls it) on a path that resolves to a git repository without a .git directory at the expected location — e.g. bare repositories, reftable/odd layouts, or a path whose discovery concluded no .git exists.
Common situations: Pointing GitButler at a bare clone; a partially deleted or corrupted .git directory; symlinked worktrees where .git resolution fails; adding a folder that was assumed to be a checkout but never was cloned.
Related errors
- Aborting due to empty branch name
- Branch name ' ' collides with existing branch
- Can only check out local branches under refs/heads, got
- Can only check out local branches under refs/heads or…
- Can only delete local branches under refs/heads, got
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/bc28f917dac6db63.
Report an issue: GitHub.
Appendix: source
Thrown at crates/gitbutler-project/src/project.rs:331
/// Try to get the `Project`, returning an error if it was not added.
pub fn try_project(self) -> anyhow::Result<Project> {
match self {
AddProjectOutcome::Added(p) => Ok(p),
AddProjectOutcome::AlreadyExists(_) => Err(anyhow::anyhow!("project already exists")),
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)