gitbutlerapp/gitbutler · error · anyhow::Error

Not in a Git repository

Error message

Not in a Git repository

What it means

Even when a repository is discovered, skill install needs a working tree to place files in (repo.workdir()). Bare repositories have none, so this error distinguishes 'found a repo, but it is bare' from the no-repository case handled just above.

Source

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

        })
    } 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())
    }
}

/// Replace version in SKILL.md content
fn inject_version(content: &str, version: &str) -> String {
    // Handle different line endings (Unix \n, Windows \r\n, or old Mac \r)
    let frontmatter_end = content
        .find("---\n\n")
        .or_else(|| content.find("---\r\n\r\n"))
        .or_else(|| content.find("---\r\r"));

    if let Some(end_pos) = frontmatter_end {
        let frontmatter = &content[..end_pos];
        let rest = &content[end_pos..];
        let updated_frontmatter =
            frontmatter.replace("version: 0.0.0", &format!("version: {version}"));
        format!("{updated_frontmatter}{rest}")

View on GitHub (pinned to caf1f223d3)

Solutions

  1. Run the command from a non-bare checkout of the repository
  2. Or use --global to install into the home directory
  3. Verify `git rev-parse --is-bare-repository` prints false before running
Defensive patterns

Strategy: validation

Validate before calling

let repo = ctx.repo.get()?;
if repo.workdir().is_none() {
    anyhow::bail!("repository is bare; install skills from a checkout or use --global");
}

Prevention

When it happens

Trigger: `but skill install <skill>` (no --global) from inside a bare clone created with `git clone --bare`, a server-side repository, or accidentally from inside a .git directory.

Common situations: Automation against bare origin repos on a server; cd-ing into .git and running but there.

Related errors


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