gitbutlerapp/gitbutler · error
project already exists
Error message
project already exists
What it means
try_project converts an AddProjectOutcome into a Project or an error. The AlreadyExists variant means the path is already registered as a project in GitButler, so adding it again is rejected with this error. The original Project is carried in the variant but discarded by this conversion.
Solutions
- Don't re-add: fetch the existing project from the project list instead (the AlreadyExists variant carries the existing Project — use it directly rather than calling try_project).
- Check whether the path is already registered before adding (list projects and compare worktree paths).
- If a stale duplicate entry is the issue, remove the old project entry and add again.
Example fix
// before
let project = outcome.try_project()?;
// after
match outcome {
AddProjectOutcome::Added(p) => Ok(p),
AddProjectOutcome::AlreadyExists(p) => Ok(p), // reuse existing
other => other.try_project(),
} Defensive patterns
Strategy: type-guard
Type guard
fn project_added(outcome: &AddProjectOutcome) -> bool {
matches!(outcome, AddProjectOutcome::Added(_) | AddProjectOutcome::AlreadyExists(_))
} Try / catch
match add_outcome {
Err(e) if e.to_string() == "project already exists" => {
// fetch existing project by path and continue
get_existing_project_by_path(path)?
}
other => other,
} Prevention
- Check the project list for the path before calling add-project.
- Reuse the Project carried by AddProjectOutcome::AlreadyExists instead of erroring.
- Make add-project calls idempotent in scripts/automation.
When it happens
Trigger: Calling try_project on an outcome returned by the add-project flow when the worktree path was previously added (AddProjectOutcome::AlreadyExists) — i.e. a duplicate add of the same directory.
Common situations: Users dragging the same folder into GitButler twice, automation re-running an add script, or re-adding a project after list refresh without checking existence.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- bare repositories are not supported
- Cannot reconcile : branch name ' ' occurs more than once
- no workdir found for repository
- non-main worktrees are not supported
- Picked commit already exists in a previous step
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/8de8d7072a4dd281.
Report an issue: GitHub.
Appendix: source
Thrown at crates/gitbutler-project/src/project.rs:318
}
impl AddProjectOutcome {
/// This is for tests only.
///
/// Unwraps the `Project` if the project was actually added.
/// Panics if it was not.
pub fn unwrap_project(self) -> Project {
match self {
AddProjectOutcome::Added(p) => p,
_ => panic!("called `AddProjectOutcome::unwrap_project()` on a non-project outcome"),
}
}
/// 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) => {View on GitHub (pinned to 58e5313667)