nikivdev/code · error
Not a git repository
Error message
Not a git repository
What it means
The git_dir locator runs `git rev-parse --git-dir`; if git exits non-zero the caller is not inside a git repository, so it bails with 'Not a git repository'. This validates the environment before any repo-relative path resolution.
Source
Thrown at src/jj.rs:3578
.output();
match output {
Ok(out) => String::from_utf8_lossy(&out.stdout)
.lines()
.filter(|l| !l.trim().is_empty())
.map(|l| l.trim().to_string())
.collect(),
Err(_) => Vec::new(),
}
}
fn git_dir(repo_root: &Path) -> Result<PathBuf> {
let output = Command::new("git")
.current_dir(repo_root)
.args(["rev-parse", "--git-dir"])
.output()
.context("failed to locate git directory")?;
if !output.status.success() {
bail!("Not a git repository");
}
let raw = String::from_utf8_lossy(&output.stdout).trim().to_string();
let dir = PathBuf::from(raw);
if dir.is_absolute() {
Ok(dir)
} else {
Ok(repo_root.join(dir))
}
}
fn workspace_default_path(repo_root: &Path, name: &str) -> Result<PathBuf> {
let home = std::env::var("HOME").context("HOME not set")?;
let repo_name = repo_root
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("repo");
Ok(PathBuf::from(home)
.join(".jj")View on GitHub (pinned to a747e741ae)
Solutions
- cd into your project checkout (the one containing .git / the jj colocated repo) and re-run the command.
- Verify `git rev-parse --git-dir` succeeds manually in that directory.
- If .git is genuinely missing, re-clone or restore the repo before using flow.
Example fix
// before cd ~ && flow sync # Not a git repository // after cd ~/code/my-project # inside the repo flow sync
Defensive patterns
Strategy: validation
Validate before calling
// shell
git rev-parse --git-dir >/dev/null 2>&1 || { echo "run from inside the repository" >&2; exit 1; } Prevention
- Anchor scripts with cd "$(git rev-parse --show-toplevel)" before invoking flow.
- Check GIT_DIR/GIT_WORK_TREE env overrides that can redirect rev-parse unexpectedly.
- Verify .git exists after cloning or restoring backups.
When it happens
Trigger: Any command that resolves the git dir (run from an unexpected cwd) executes `git rev-parse --git-dir` outside a work tree or in a repo where git fails (corrupt config, missing .git).
Common situations: Running flow from a subdirectory outside the repo, from $HOME, or in a checkout where .git was deleted; PATH lacking a working git binary causing spawn/context errors upstream; GIT_DIR env pointing at a nonexistent location.
Related errors
- failed to resolve git repo root
- git repo root was empty
- Not a git repository
- not inside a git repository
- git config --global {} failed
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/4e08d0bf47834fc5.
Report an issue: GitHub.