gitbutlerapp/gitbutler · error

Not in a Git repository

Error message

Not in a Git repository

What it means

After obtaining the repository handle from the Context, local skill installation needs the working-directory path via `repo.workdir()`. This error is thrown when `workdir()` returns `None`, i.e., the resolved repository is bare and has no working tree in which to install skill files.

Solutions

  1. Run the install from a normal (non-bare) clone of the repository.
  2. Clone a working copy first (`git clone <url> repo && cd repo`) and install there.
  3. Check `git rev-parse --is-bare-repository`; if true, switch to a worktree-equipped checkout.

Example fix

// before
cd /srv/repo.git && but skill install ./my-skill

// after
git clone /srv/repo.git ~/repo && cd ~/repo && but skill install ./my-skill
Defensive patterns

Strategy: validation

Validate before calling

let repo = ctx.repo.get()?;
if repo.workdir().is_none() {
    anyhow::bail!("repository is bare; skill install needs a working tree");
}

Type guard

fn is_bare(repo: &gix::Repository) -> bool { repo.workdir().is_none() }

Try / catch

match install(ctx, args) {
    Err(e) if e.to_string() == "Not in a Git repository" =>
        eprintln!("Use a non-bare clone for local skill install"),
    other => other?,
}

Prevention

When it happens

Trigger: Running `but skill install` inside a bare repository (e.g., a bare server-side clone), where the Context resolves to a repo whose `workdir()` is `None`.

Common situations: SSH-ing into a bare deployment repo and running the CLI there; pointing the tool at `.git` directly; CI setups that clone with `--bare`.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at crates/but/src/command/skill/mod.rs:534

        })
    } else {
        None
    }
}

/// Get the base directory for installation (repo root or home directory)
fn get_base_dir(ctx: Option<&mut Context>, global: bool) -> Result<PathBuf> {
    if global {
        home_dir().ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))
    } else {
        let ctx = ctx.ok_or_else(|| {
            anyhow::anyhow!(
                "Not in a git repository. Use --global to install globally, or run from within a repository."
            )
        })?;
        let repo = ctx.repo.get()?;
        repo.workdir()
            .ok_or_else(|| anyhow::anyhow!("Not in a Git repository"))
            .map(|p| p.to_path_buf())
    }
}

/// Byte range of the frontmatter's closing `---` line plus the blank line
/// after it, for any line ending (Unix, Windows, or old Mac). `None` unless
/// the content opens with a frontmatter block, so a Markdown `---` rule in a
/// document without one is never mistaken for the delimiter.
fn frontmatter_close(content: &str) -> Option<std::ops::Range<usize>> {
    if !(content.starts_with("---\n") || content.starts_with("---\r")) {
        return None;
    }
    let after_opener = "---".len();
    ["---\n\n", "---\r\n\r\n", "---\r\r"]
        .into_iter()
        .find_map(|delimiter| {
            content[after_opener..]
                .find(delimiter)

View on GitHub (pinned to 58e5313667)