Cargo "failed to get X as a dependency" in CI
failed to get X as a dependency of package Y is Cargo’s wrapper message. The real cause - an index update failure, a download error, or an unreachable git source - is in the Caused by: lines beneath it.
What this error means
cargo prints failed to get <crate> as a dependency of package <yours> followed by one or more Caused by: lines. The wrapper is generic; the actual failure (network, auth, missing rev) is in the chain below.
error: failed to get `anyhow` as a dependency of package `app v0.1.0`
Caused by:
failed to load source for dependency `anyhow`
Caused by:
Unable to update https://github.com/dtolnay/anyhow
Caused by:
failed to clone into: /home/runner/.cargo/git/db/anyhow-...Common causes
A git or path source could not be loaded
For a git = "..." dependency, Cargo could not clone or update the repo - a bad URL, a deleted branch/rev, or missing credentials for a private repo.
An underlying index or download failure
The wrapper often sits on top of a failed to update registry or failed to download cause - a transient network issue fetching the crate.
How to fix it
Read the full Caused-by chain
- Scroll to the deepest
Caused by:line - that is the real error. - For a git source, verify the URL, branch, tag, or rev exists and is reachable.
- For a private git repo, configure credentials (a token or SSH key) for the runner.
Pin a git dependency to a real rev
A dropped branch or moved tag breaks the clone. Pin an existing commit so it stays resolvable.
[dependencies]
anyhow = { git = "https://github.com/dtolnay/anyhow", rev = "abc1234" }How to prevent it
- Pin git dependencies to a commit or tag that won’t disappear.
- Configure credentials for private git/registry sources in CI.
- Cache
~/.cargo/gitso clones don’t repeat on every run.