{"record":{"id":"75c00f7fba41941f","repo":"gitbutlerapp/gitbutler","slug":"no-git-repository-found-at-nplease-run-but-set","errorCode":null,"errorMessage":"No git repository found at {}\\nPlease run 'but setup' to initialize the project.","messagePattern":"No git repository found at (.+?)\\\\nPlease run 'but setup' to initialize the project\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/setup.rs","lineNumber":111,"sourceCode":"///   exceeds the configured interval\n///\n/// When a background sync is initiated and the output format allows human UI messages, a\n/// message is written to the output channel showing how long ago the last sync occurred\n/// (e.g., \"Last fetch was 15m ago. Initiated a background fetch...\"). The time is formatted\n/// as seconds (s), minutes (m), hours (h), or days (d) depending on the elapsed duration.\n///\n/// When `background_sync` is `BackgroundSync::Disabled`, no background sync is performed\n/// regardless of the configured interval.\npub fn init_ctx(\n    args: &Args,\n    options: InitCtxOptions,\n    out: &mut OutputChannel,\n) -> anyhow::Result<Context> {\n    let app_settings = crate::app_settings()?;\n    // lets try to get the repo from the current directory\n    let repo = match gix::discover(&args.current_dir) {\n        Ok(repo) => repo,\n        Err(_) => anyhow::bail!(\n            \"No git repository found at {}\\nPlease run 'but setup' to initialize the project.\",\n            &args.current_dir.display()\n        ),\n    };\n\n    // Check if we're on gitbutler/workspace with non-workspace commits on top\n    // before creating the context\n    if matches!(options.workspace_check, WorkspaceCheck::Enabled) {\n        check_workspace_commits_before_init(&repo, out)?;\n    }\n\n    let (ctx, fetch_interval_minutes, last_fetch) = {\n        let Some(workdir) = repo.workdir() else {\n            anyhow::bail!(\"Bare repositories are not supported.\");\n        };\n        #[cfg(feature = \"legacy\")]\n        {\n            use but_ctx::LegacyProject;","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but/src/setup.rs#L93-L129","documentation":"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.","triggerScenarios":"Running any workspace command (but branch, but sync, ...) from a directory outside any git worktree, or from a cwd whose repo was deleted.","commonSituations":"Wrong terminal tab, a freshly created project that was never git-init'ed, scripts run from $HOME, ssh sessions landing in /.","solutions":["cd into the git repository and retry","If the project is not a repo yet: git init (or clone it), then run `but setup`","Verify the cwd is the worktree and not an adjacent or deleted directory"],"exampleFix":"$ cd /tmp && but branch list\n# No git repository found at /tmp\n$ cd ~/projects/app && but branch list","handlingStrategy":"validation","validationCode":"if gix::discover(&cwd).is_err() {\n    // not a repo: git init/clone first, or refuse before invoking but\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify repo discovery (or `git rev-parse --show-toplevel`) before any but invocation","Guard scripts to refuse running outside a worktree","Keep project onboarding steps that git init before calling but setup"],"tags":["git","repository","context","cli"],"backgroundTag":"not-a-git-repository","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}