denoland/deno · error · anyhow::Error

Failed to run `git `: . Is git installed and on PATH?

Error message

Failed to run `git {}`: {err}. Is git installed and on PATH?

What it means

run_git (cli/util/git.rs:11-24) spawns the system `git` for features such as `deno test --changed` (changed_files_from_git, cli/tools/test/mod.rs:2183). This variant fires when the spawn itself fails — overwhelmingly `git` not installed or not reachable on PATH (io ErrorKind NotFound), or a broken PATH in the calling environment.

Solutions

  1. Install git: apt-get install -y git / brew install git / winget install Git.Git, then verify with `git --version` in the same shell.
  2. Fix PATH so the git binary directory is included (e.g. /usr/bin, /opt/homebrew/bin, C:\\Program Files\\Git\\cmd).
  3. If git is not an option, drop the git-dependent flag (run deno test without --changed).

Example fix

# before
$ deno test --changed
error: Failed to run `git rev-parse --show-toplevel`: ... Is git installed and on PATH?

# after — install git in the image / environment
RUN apt-get update && apt-get install -y git
deno test --changed
Defensive patterns

Strategy: validation

Validate before calling

# Gate git-dependent features on git being present
command -v git >/dev/null 2>&1 || { echo 'git not on PATH — skipping --changed'; exit 0; }
deno test --changed

Prevention

When it happens

Trigger: deno test --changed in a slim container or cron job where git is absent; PATH stripped/reset by a wrapper; git installed as a shell function or alias rather than an executable.

Common situations: Minimal Docker images (deno:* without git), CI stages that prune toolchain, Windows machines with Git Bash not on PATH, scheduled tasks with sanitized environments.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/a0db4c376dcd7ea2. Report an issue: GitHub.

Appendix: 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 9ad36f7a2c)