gitbutlerapp/gitbutler · error

No git repository found at {}\nPlease run 'but setup' to ini

Error message

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

What it means

Nearly every `but` workspace command begins in init_ctx by discovering a git repository from the current directory via gix::discover. If discovery fails (no .git in the cwd or any parent), there is no project to operate on, so the command aborts with the attempted path and a hint to run `but setup` inside the project.

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 gix::discover(&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 caf1f223d3)

Solutions

  1. cd into the git repository and retry
  2. If the project is not a repo yet: git init (or clone it), then run `but setup`
  3. Verify the cwd is the worktree and not an adjacent or deleted directory

Example fix

$ cd /tmp && but branch list
# No git repository found at /tmp
$ cd ~/projects/app && but branch list
Defensive patterns

Strategy: validation

Validate before calling

if gix::discover(&cwd).is_err() {
    // not a repo: git init/clone first, or refuse before invoking but
}

Prevention

When it happens

Trigger: Running any workspace command (but branch, but sync, ...) from a directory outside any git worktree, or from a cwd whose repo was deleted.

Common situations: Wrong terminal tab, a freshly created project that was never git-init'ed, scripts run from $HOME, ssh sessions landing in /.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/75c00f7fba41941f. Report an issue: GitHub.