nikivdev/code · error
not inside a git repository
Error message
not inside a git repository
What it means
git_root runs `git rev-parse --show-toplevel` to find the enclosing repository. If the command exits non-zero — which happens when the current directory is not inside any git work tree — the tool bails with 'not inside a git repository'. Publishing requires a repo because it snapshots and pushes the current project.
Source
Thrown at src/publish.rs:678
let mut current = start.to_path_buf();
loop {
let candidate = current.join("flow.toml");
if candidate.exists() {
return Some(candidate);
}
if !current.pop() {
return None;
}
}
}
fn git_root() -> Result<PathBuf> {
let output = Command::new("git")
.args(["rev-parse", "--show-toplevel"])
.output()
.context("failed to locate git root")?;
if !output.status.success() {
bail!("not inside a git repository");
}
let path = String::from_utf8_lossy(&output.stdout).trim().to_string();
Ok(PathBuf::from(path))
}
fn ensure_git_repo(repo_root: &Path) -> Result<()> {
let _ = vcs::ensure_jj_repo_in(repo_root)?;
let git_dir = repo_root.join(".git");
if !git_dir.exists() {
Command::new("git")
.args(["init"])
.current_dir(repo_root)
.status()
.context("failed to initialize git")?;
}
let has_commits = Command::new("git")
.args(["rev-parse", "HEAD"])View on GitHub (pinned to a747e741ae)
Solutions
- Run `git init` in the project directory (and commit at least once) before publishing
- cd into your actual repository root
- If the .git folder is missing due to a copy/mount, restore it or re-clone
Example fix
// before /tmp/my-app $ f publish Error: not inside a git repository // after /tmp/my-app $ git init && git add -A && git commit -m init /tmp/my-app $ f publish
Defensive patterns
Strategy: validation
Validate before calling
let out = std::process::Command::new("git")
.args(["rev-parse","--show-toplevel"])
.output()?;
if !out.status.success() {
eprintln!("current directory is not inside a git repository; run `git init` or cd into the repo");
std::process::exit(1);
} Try / catch
match run(opts) {
Err(e) if e.to_string().contains("not inside a git repository") => {
eprintln!("cd into your repo or run `git init` first");
}
other => other?,
} Prevention
- Verify `git rev-parse --show-toplevel` succeeds before publishing
- Don't strip .git directories when copying/mounting project trees
- Initialize and commit new projects before running publish
When it happens
Trigger: Running `f publish` (or gitedit publish) from a directory with no .git anywhere in its ancestors: an extracted archive, a fresh empty folder, or after `rm -rf .git`.
Common situations: Publishing a scratch directory that was never `git init`ed; being in a subdirectory of a non-repo (e.g. /tmp); Docker containers mounting only source files without the .git directory.
Related errors
- Not a git repository
- not inside a git repository
- sync is blocked
- jj git export retry loop should always return
- Lin.app is not running
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/cee26f6c88625859.
Report an issue: GitHub.