{"record":{"id":"4a3be14ffb75dd5d","repo":"gitbutlerapp/gitbutler","slug":"no-git-repository-found-run-but-setup-init-to-initialize-a","errorCode":null,"errorMessage":"No git repository found - run `but setup --init` to initialize a new repository.","messagePattern":"No git repository found - run `but setup --init` to initialize a new repository\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/setup.rs","lineNumber":168,"sourceCode":"                    )?;\n                    writeln!(out)?;\n                }\n                Ok(repo)\n            }\n            // If prompting is available, try to set up a new repo interactively.\n            else if out.can_prompt() {\n                match setup_new_repo(repo_path, out) {\n                    Ok(repo) => Ok(repo),\n                    Err(e) => {\n                        if let Some(out) = out.for_human() {\n                            writeln!(\n                                out,\n                                \"{}\",\n                                t.error\n                                    .paint(format!(\"Failed to initialize repository: {e}\"))\n                            )?;\n                        }\n                        anyhow::bail!(\n                            \"No git repository found - run `but setup --init` to initialize a new repository.\"\n                        );\n                    }\n                }\n            } else {\n                anyhow::bail!(\n                    \"No git repository found - run `but setup --init` to initialize a new repository.\"\n                );\n            }\n        }\n    }\n}\n\n// setup a gitbutler project for the repository at `repo_path`\npub(crate) fn repo(\n    ctx: &mut Context,\n    repo_path: &Path,\n    out: &mut OutputChannel,","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/setup.rs#L150-L186","documentation":"`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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Run `but setup --init` in the directory to initialize a repository non-interactively","Or run `git init` manually, then re-run the `but` command","Fix the underlying init failure: set user.name/user.email (`git config --global user.name ...`), check write permissions","Verify you are in the intended directory (use `but` from the project root, or `-C <path>`)"],"exampleFix":"// before\nbut status   # in a non-repo directory\n\n// after\nbut setup --init\nbut status","handlingStrategy":"try-catch","validationCode":"# bail out early if not a git repo\n[ -d .git ] || git rev-parse --git-dir >/dev/null 2>&1 || but setup --init","typeGuard":null,"tryCatchPattern":"match but_command_result {\n    Err(e) if e.to_string().contains(\"No git repository found\") => {\n        run(\"but setup --init\")?;\n        run(\"but status\")\n    }\n    other => other,\n}","preventionTips":["Run `but setup --init` once when creating a new project","Check `git rev-parse --git-dir` succeeds before invoking but commands","Set git user.name/user.email before first init so the empty initial commit succeeds","Run from the repository root or pass the path explicitly"],"tags":["cli","git","repository","init","setup"],"backgroundTag":"file-not-found","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}