denoland/deno · error · anyhow::Error
Failed to run `git {}`: {err}. Is git installed and on PATH?
Error message
Failed to run `git {}`: {err}. Is git installed and on PATH? What it means
Runs `git <args>` via `std::process::Command` in the given cwd. If the process cannot be spawned at all — git not installed, not on PATH, or an exec-bit problem — the io error is wrapped together with the exact git command and a PATH hint.
Source
Thrown at cli/util/git.rs:19
// Copyright 2018-2026 the Deno authors. MIT license.
use std::path::Path;
use std::process::Stdio;
use deno_core::anyhow::anyhow;
use deno_core::error::AnyError;
use tokio::process::Command;
/// Run `git` with `args` in `cwd`, returning stdout on success.
pub fn run_git(cwd: &Path, args: &[&str]) -> Result<String, AnyError> {
let output = match std::process::Command::new("git")
.current_dir(cwd)
.args(args)
.output()
{
Ok(output) => output,
Err(err) => {
return Err(anyhow!(
"Failed to run `git {}`: {err}. Is git installed and on PATH?",
args.join(" ")
));
}
};
if !output.status.success() {
return Err(anyhow!(
"`git {}` failed: {}",
args.join(" "),
String::from_utf8_lossy(&output.stderr).trim()
));
}
Ok(String::from_utf8_lossy(&output.stdout).into_owned())
}
pub async fn check_if_git_repo_dirty(cwd: &Path) -> Option<String> {
let bin_name = if cfg!(windows) { "git.exe" } else { "git" };
View on GitHub (pinned to 89f33cbef2)
Solutions
- Install git and verify it resolves in the same shell deno runs under: `git --version` (apt-get install git / apk add git / xcode-select --install)
- Fix PATH for the deno process — service units, cron entries, and containers often need it set explicitly
- If git is intentionally absent in the environment, avoid the code path that requires it
Example fix
# before: distroless-style container without git
deno release # -> Failed to run `git ...`
# after (Dockerfile)
RUN apt-get update && apt-get install -y git
ENV PATH="/usr/bin:${PATH}" Defensive patterns
Strategy: validation
Validate before calling
# bash: assert git is reachable before running git-dependent deno commands
command -v git >/dev/null 2>&1 || { echo "git required but not on PATH" >&2; exit 1; }
deno release Prevention
- Install git in runtime images, not only build stages
- Set PATH explicitly in systemd/cron/container definitions that run deno
- Add a `git --version` smoke check to CI before git-dependent steps
When it happens
Trigger: Any deno feature that shells out to git (for example repository-cleanliness checks) on a machine where the `git` binary is missing or PATH omits its directory.
Common situations: Minimal container images (distroless, slim) without git; CI images where git exists only in the build stage; systemd units, cron, or sanitized environments with a stripped PATH.
Related errors
- Unable to construct URL from the path of cwd: {}
- `git {}` failed: {}
- The bench name can't be empty
- Unexpected third argument to Deno.bench()
- Expected 'fn' field in the first argument to be a bench func
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/a0db4c376dcd7ea2.
Report an issue: GitHub.