{"id":"8d1277aeeb05ef67","repo":"rust-lang/cargo","slug":"can-t-checkout-from-you-are-in-the-offline-m","errorCode":null,"errorMessage":"can't checkout from '{}': you are in the offline mode ({offline_flag})","messagePattern":"can't checkout from '(.+?)': you are in the offline mode \\((.+?)\\)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/sources/git/source.rs","lineNumber":219,"sourceCode":"                    .gctx\n                    .offline_flag()\n                    .expect(\"always present when `!network_allowed`\");\n                let rev = db.resolve(&git_ref).with_context(|| {\n                    format!(\n                        \"failed to lookup reference in preexisting repository, and \\\n                         can't check for updates in offline mode ({offline_flag})\"\n                    )\n                })?;\n                (db, rev)\n            }\n\n            // ... otherwise we use this state to update the git database. Note\n            // that we still check for being offline here, for example in the\n            // situation that we have a locked revision but the database\n            // doesn't have it.\n            (locked_rev, db) => {\n                if let Some(offline_flag) = self.gctx.offline_flag() {\n                    anyhow::bail!(\n                        \"can't checkout from '{}': you are in the offline mode ({offline_flag})\",\n                        self.remote.url()\n                    );\n                }\n\n                if !self.quiet {\n                    let scope = if is_submodule {\n                        \"submodule\"\n                    } else {\n                        \"repository\"\n                    };\n                    self.gctx\n                        .shell()\n                        .status(\"Updating\", format!(\"git {scope} `{}`\", self.remote.url()))?;\n                }\n\n                trace!(\"updating git source `{:?}`\", self.remote);\n","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/sources/git/source.rs#L201-L237","documentation":"Cargo refuses to update/checkout a git dependency because the process is running with `--offline` or `--frozen` (the `{offline_flag}` value). It fires in `GitSource::blockish_get` once Cargo has exhausted every local option: the locked revision isn't present in the on-disk git database, or a deferred branch/tag/reference can't be resolved from the existing clone, so resolving it would require hitting the network — which the flag forbids. The remote URL that Cargo wanted to fetch from is interpolated into the message.","triggerScenarios":"Running `cargo build --offline` / `cargo build --frozen` (or having `net.offline = true` in config) when (a) it's the first build of a git dependency, (b) `Cargo.lock` was updated to point at a newer git commit than what's cached in `~/.cargo/git/db/`, or (c) the git reference (`branch`/`tag`/`rev`) can't be resolved against the locally cloned database. Reached via the `(locked_rev, db) =>` arm at src/sources/git/source.rs:217.","commonSituations":"CI pipelines that pass `--frozen`/`--offline` for reproducibility but forgot to populate or vendor the git sources; air-gapped build machines; switching git branches of the consuming project so `Cargo.lock` references an uncached OID; git dependency using `branch = \"main\"` while offline so the deferred ref can't be resolved.","solutions":["Run once WITHOUT the flag (e.g. plain `cargo fetch`) so the git database under `~/.cargo/git/db/` is populated, then retry with `--offline`.","If you must stay offline, vendor the dependency (`cargo vendor`) and add a `[source]` replacement mapping the git URL to the vendored path.","Pin the dependency to a concrete `rev = \"<full 40-char commit hash>\"` that you have verified is already present in the local git cache.","For `--frozen`: refresh `Cargo.lock` on a networked machine and commit it, so the frozen build never needs a fresh fetch.","Remove `net.offline = true` from `.cargo/config.toml` if it was set globally and is no longer intended."],"exampleFix":"# before\ncargo build --offline   # git dep 'foo' locked rev not in cache -> error\n\n# after (option A: populate then offline)\ncargo fetch && cargo build --offline\n\n# after (option B: vendor)\ncargo vendor vendored\n# .cargo/config.toml\n[source.my-git-dep]\ngit = \"https://github.com/org/foo\"\nreplace-with = \"vendored-sources\"\n[source.vendored-sources]\ndirectory = \"vendored\"","handlingStrategy":"validation","validationCode":"# Before building offline, confirm the git dep's locked OID is cached locally.\n# (shell)\n# 1. ensure you have network for the one-time populate\ncargo fetch\n# 2. only then go offline\ncargo build --offline\n\n# In Rust tooling that wraps cargo, check before invoking:\nif offline_enabled && !git_db_has_oid(&db, locked_oid) {\n    return Err(format!(\"git dep {dep} not cached; cannot build --offline\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `cargo fetch` on a networked host before any `--offline`/`--frozen` build.","Vendor git dependencies (`cargo vendor`) for fully offline reproducible builds.","Pin git deps to full 40-char commit hashes so the lock is unambiguous."],"tags":["cargo","git","offline","network","config"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}