rust-lang/cargo · error
`git` is not available help: to still use `git` for fetching
Error message
`git` is not available help: to still use `git` for fetching, please install it help: to use Cargo's native git support, re-try with `net.git-fetch-with-cli = false` https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
What it means
In `fetch_with_cli` (called by `fetch`), Cargo is configured to shell out to the `git` CLI for fetching (`net.git-fetch-with-cli = true`), but `git_version()` returned None because no usable `git` executable was found on PATH. Cargo aborts the fetch with guidance to install git or fall back to its native (gitoxide/libgit2) fetch support.
Source
Thrown at src/sources/git/utils.rs:1255
/// hatch for users that would prefer to use `git`-the-CLI for fetching
/// repositories instead of `libgit2`-the-library. This should make more
/// flavors of authentication possible while also still giving us all the
/// speed and portability of using `libgit2`.
///
/// [1]: https://doc.rust-lang.org/nightly/cargo/reference/config.html#netgit-fetch-with-cli
#[tracing::instrument(skip(repo, gctx))]
fn fetch_with_cli(
repo: &git2::Repository,
url: &str,
refspecs: &[String],
tags: bool,
shallow: gix::remote::fetch::Shallow,
gctx: &GlobalContext,
) -> CargoResult<()> {
debug!(target: "git-fetch", backend = "git-cli");
let Some(git_version) = git_version() else {
anyhow::bail!(
"`git` is not available
help: to still use `git` for fetching, please install it
help: to use Cargo's native git support, re-try with `net.git-fetch-with-cli = false`
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli"
);
};
let mut cmd = ProcessBuilder::new("git");
// Avoid potential for unused work that may also hang (#15775)
cmd.arg("-c").arg("core.fsmonitor=false");
// Avoid warnings with `--no-show-forced-updates`
cmd.arg("-c").arg("advice.fetchShowForcedUpdates=false");
// Have 429's retried in git, where supported
let max_retries = gctx
.net_config()?
.retry
.unwrap_or(network::retry::MAX_RETRY_DEFAULT);
cmd.arg("-c").arg(format!("http.maxRetries={max_retries}"));View on GitHub (pinned to 42eee92bc9)
Solutions
- Install git (apt-get install git / choco install git / brew install git) or add its bin directory to PATH.
- Set `net.git-fetch-with-cli = false` in .cargo/config.toml (or unset CARGO_NET_GIT_FETCH_WITH_CLI) to use Cargo's native git support.
- Verify with `git --version` in the same shell/CI job that cargo runs in.
- If git is intentionally unavailable, vendor dependencies (`cargo vendor`) to avoid network git fetches.
Example fix
// before (.cargo/config.toml) [net] git-fetch-with-cli = true // after: either install git, or switch back to native fetch [net] git-fetch-with-cli = false
Defensive patterns
Strategy: validation
Validate before calling
let have_git = std::process::Command::new("git").arg("--version").output().is_ok();
assert!(have_git, "git must be on PATH when net.git-fetch-with-cli = true"); Prevention
- Install git as a base-layer step in all CI/Docker images that run cargo.
- Only enable net.git-fetch-with-cli when private-registry auth actually requires it.
- Prefer `cargo vendor` or a sparse registry for hermetic builds with no git dependency.
- Run `git --version` as an early CI sanity check.
When it happens
Trigger: Running cargo fetch/build/update with `net.git-fetch-with-cli = true` in .cargo/config.toml (or CARGO_NET_GIT_FETCH_WITH_CLI=true) while the `git` binary is absent from PATH or not executable.
Common situations: CI containers/minimal Docker images without git installed; Windows machines without Git for Windows in PATH; restricted sandboxes where git was removed; typo'd PATH in CI environment.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- can't checkout from '{}': you are in the offline mode ({offl
- attempting to update a git repository, but {offline_flag} wa
- could not find `base-sha` for `{UPSTREAM_BRANCH}`, pass it i
- cannot specify a git URL (`{url}`) with a version (`{v}`).
- {} files in the working directory contain changes that were
AI-assisted analysis of rust-lang/cargo@42eee92bc9 (2026-09-08).
Data as JSON: /api/errors/fda344b9d4ca944c.
Report an issue: GitHub.