gitbutlerapp/gitbutler · error

No git repository found - run `but setup --init` to…

Error message

No git repository found - run `but setup --init` to initialize a new repository.

What it means

`find_or_initialize_repo` first tries `gix::open(repo_path)`. When that fails and `--init` was requested but interactive setup (`setup_new_repo`) also errored, the CLI gives up with this message telling the user to run `but setup --init`. The inner error from interactive initialization is printed before bailing.

Solutions

  1. Run `but setup --init` in the directory to initialize a repository non-interactively
  2. Or run `git init` manually, then re-run the `but` command
  3. Fix the underlying init failure: set user.name/user.email (`git config --global user.name ...`), check write permissions
  4. Verify you are in the intended directory (use `but` from the project root, or `-C <path>`)

Example fix

// before
but status   # in a non-repo directory

// after
but setup --init
but status
Defensive patterns

Strategy: try-catch

Validate before calling

# bail out early if not a git repo
[ -d .git ] || git rev-parse --git-dir >/dev/null 2>&1 || but setup --init

Try / catch

match but_command_result {
    Err(e) if e.to_string().contains("No git repository found") => {
        run("but setup --init")?;
        run("but status")
    }
    other => other,
}

Prevention

When it happens

Trigger: Running a `but` command in a directory that is not a git repository without `--init`, when prompting is available but interactive setup fails (e.g. user declines, or `git init`/initial-commit creation fails due to permissions or a bad user.name/user.email config).

Common situations: Running `but` in a fresh project folder before `git init`; a corrupted `.git` directory that gix cannot open; missing git identity config so the initial empty commit fails; read-only filesystem preventing init.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

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

                    )?;
                    writeln!(out)?;
                }
                Ok(repo)
            }
            // If prompting is available, try to set up a new repo interactively.
            else if out.can_prompt() {
                match setup_new_repo(repo_path, out) {
                    Ok(repo) => Ok(repo),
                    Err(e) => {
                        if let Some(out) = out.for_human() {
                            writeln!(
                                out,
                                "{}",
                                t.error
                                    .paint(format!("Failed to initialize repository: {e}"))
                            )?;
                        }
                        anyhow::bail!(
                            "No git repository found - run `but setup --init` to initialize a new repository."
                        );
                    }
                }
            } else {
                anyhow::bail!(
                    "No git repository found - run `but setup --init` to initialize a new repository."
                );
            }
        }
    }
}

// setup a gitbutler project for the repository at `repo_path`
pub(crate) fn repo(
    ctx: &mut Context,
    repo_path: &Path,
    out: &mut OutputChannel,

View on GitHub (pinned to 58e5313667)