gitbutlerapp/gitbutler · error

No git repository found at

Error message

No git repository found at {}
Please run 'but setup' to initialize the project.

What it means

During CLI context initialization, `init_ctx` tries to discover the main git repository from the current directory using but_ctx::discover_main_repo. If discovery fails, it aborts with this message telling the user to run `but setup` to initialize the project. In short: you invoked a but command outside any git repository it can find.

Solutions

  1. cd into your git repository (or its subdirectory) and rerun the command.
  2. If the project is new, run `git init` and then `but setup`.
  3. Run `but setup` in the intended project directory to initialize GitButler metadata.

Example fix

// before (in ~/random-dir)
but status
// after
cd ~/my-project && but status   # or: git init && but setup
Defensive patterns

Strategy: validation

Validate before calling

# ensure current dir is inside a git repo before running but
git rev-parse --show-toplevel >/dev/null 2>&1 || { echo "Not a git repo; run but setup"; exit 1; }

Prevention

When it happens

Trigger: Running any but command in a directory that is not inside a git repository (discover_main_repo returns Err for args.current_dir).

Common situations: Running `but` in a home directory or non-repo folder; typos in cd; working in a fresh checkout before any git init; forgetting that but requires an existing git repo as its base.

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/3afb0a4caad56401. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/setup.rs:111

///   exceeds the configured interval
///
/// When a background sync is initiated and the output format allows human UI messages, a
/// message is written to the output channel showing how long ago the last sync occurred
/// (e.g., "Last fetch was 15m ago. Initiated a background fetch..."). The time is formatted
/// as seconds (s), minutes (m), hours (h), or days (d) depending on the elapsed duration.
///
/// When `background_sync` is `BackgroundSync::Disabled`, no background sync is performed
/// regardless of the configured interval.
pub fn init_ctx(
    args: &Args,
    options: InitCtxOptions,
    out: &mut OutputChannel,
) -> anyhow::Result<Context> {
    let app_settings = crate::app_settings()?;
    // lets try to get the repo from the current directory
    let repo = match but_ctx::discover_main_repo(&args.current_dir) {
        Ok(repo) => repo,
        Err(_) => anyhow::bail!(
            "No git repository found at {}\nPlease run 'but setup' to initialize the project.",
            &args.current_dir.display()
        ),
    };

    // Check if we're on gitbutler/workspace with non-workspace commits on top
    // before creating the context
    if matches!(options.workspace_check, WorkspaceCheck::Enabled) {
        check_workspace_commits_before_init(&repo, out)?;
    }

    let (ctx, fetch_interval_minutes, last_fetch) = {
        let Some(workdir) = repo.workdir() else {
            anyhow::bail!("Bare repositories are not supported.");
        };
        #[cfg(feature = "legacy")]
        {
            use but_ctx::LegacyProject;

View on GitHub (pinned to 58e5313667)