gitbutlerapp/gitbutler · error
Not in a git repository. Use --global to install globally…
Error message
Not in a git repository. Use --global to install globally, or run from within a repository.
What it means
When installing a skill locally (no `--global`), the base directory is derived from the current repository via the CLI `Context`. This error is thrown when that context is `None`, meaning the command was not run inside a Git repository that GitButler could recognize.
Solutions
- `cd` into your Git repository before running `but skill install`.
- If you actually want a user-level install, add the `--global` flag.
- Verify the directory is a repo: `git rev-parse --show-toplevel` should print a path.
Example fix
// before cd /tmp && but skill install ./my-skill // after cd /path/to/repo && but skill install ./my-skill # or: but skill install --global ./my-skill
Defensive patterns
Strategy: validation
Validate before calling
// shell, before running the command
git rev-parse --show-toplevel >/dev/null 2>&1 || { echo "not in a git repo; cd into one or use --global"; exit 1; } Try / catch
match install(opts) {
Err(e) if e.to_string().contains("Not in a git repository") =>
eprintln!("cd into a repo or pass --global"),
other => other?,
} Prevention
- Run `git rev-parse --show-toplevel` first in scripts to confirm repo context.
- Add `--global` when installing from non-repo directories.
- Avoid running the CLI from $HOME or /tmp in automation.
When it happens
Trigger: Running `but skill install <skill>` (without `--global`) outside any Git repository, or in a directory where the Context failed to initialize (no `.git` found), so `get_base_dir` receives `ctx: None`.
Common situations: Running the command in `$HOME`, `/tmp`, or a plain folder that is not a git repo; typo'd working directory in scripts; intending a global install but forgetting the `--global` flag.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Aborting due to empty branch name
- Bare repositories are not supported.
- Branch ' ' not found
- Branch ' ' not found when checking for conflicts
- Branch " " has no conflicted commits.
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/e086adc59077bbca.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/skill/mod.rs:528
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())
}
}
/// 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;
}View on GitHub (pinned to 58e5313667)