gitbutlerapp/gitbutler · error · anyhow::Error
Not in a git repository. Use --global to install globally, o
Error message
Not in a git repository. Use --global to install globally, or run from within a repository.
What it means
`but skill install` without --global installs into the current git repository's root, which it obtains from a discovered Context. When no repository is found in or above the cwd, ctx is None and the command explains the two valid modes: run inside a repo, or pass --global.
Source
Thrown at crates/but/src/command/skill/mod.rs:416
home_dir().map(|home| {
if path_str == "~" {
home
} else {
home.join(&path_str[2..])
}
})
} 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"));
View on GitHub (pinned to caf1f223d3)
Solutions
- cd into the target git repository and rerun the command
- Or pass --global to install into the home directory instead
- In scripts, gate the call on `git rev-parse --git-dir` succeeding
Example fix
# before ~ $ but skill install my-skill # not a repo -> error # after ~ $ but skill install my-skill --global # or cd ~/src/myrepo && but skill install my-skill
Defensive patterns
Strategy: validation
Validate before calling
match gix::discover(std::env::current_dir()?) {
Ok(_) => { /* repo-local install is safe */ }
Err(_) if !global => anyhow::bail!("run inside a git repository or pass --global"),
Err(_) => {}
} Prevention
- Verify `git rev-parse --git-dir` succeeds before headless installs
- Default to --global when the script's cwd is not guaranteed to be a repo
When it happens
Trigger: Running `but skill install <skill>` in a plain directory with no .git in it or any parent (home dir, /tmp, a fresh folder) without --global.
Common situations: Installing a skill from the home directory; CI steps that run before the repo checkout step; forgetting the --global flag.
Related errors
- Could not detect an existing GitButler skill installation. R
- No supported agent was detected. In non-interactive mode, sp
- Human input required - run this in a terminal, or specify --
- Cannot use both --detect and --path options together
- Installation path {} is a file, not a directory. Please spec
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/e086adc59077bbca.
Report an issue: GitHub.