{"record":{"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":null,"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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/sources/git/source.rs#L201-L237","documentation":"Cargo cannot fetch a git dependency because the user invoked it with an offline flag (`--offline`) while the locally cached git database does not contain the locked/required revision. The error fires in the fallthrough arm of `fetch_db` after Cargo confirmed the revision is missing locally and a network update would be required. The `{remote_url}` placeholder shows which git source failed.","triggerScenarios":"Calling a Cargo build/fetch command with `--offline` (or `CARGO_NET_OFFLINE=true`) when a git dependency's `Cargo.lock` pins a commit that is not present in the local `~/.cargo/git/db` cache. Also triggered when a previously locked revision was garbage-collected or the db was deleted.","commonSituations":"Running CI or building on an air-gapped machine with `--offline` after `Cargo.lock` was updated against a newer commit on a networked machine; switching branches whose `Cargo.lock` references a git commit never fetched locally; corrupted/pruned cargo git cache.","solutions":["Remove `--offline` / unset `CARGO_NET_OFFLINE=true` and re-run so Cargo can fetch the missing commit.","Run `cargo fetch` (without `--offline`) on a networked machine to populate `~/.cargo/git/db`, then transfer or share that cache to the offline machine.","Pin the git dependency to a revision already present locally: inspect `~/.cargo/git/db/<repo>.db` with `git log` and update `rev = \"...\"` in `Cargo.toml` / `Cargo.lock` to match.","Clear the stale cache with `cargo cache --autoclean` (or remove `~/.cargo/git/db/<ident>`) then fetch online once to rebuild it."],"exampleFix":"# before: Cargo.toml pins a commit not cached locally, run with --offline\n[dependencies]\nmy-lib = { git = \"https://github.com/user/repo\", rev = \"abc1234\" }\n\n# fix option 1: fetch online once\ncargo fetch\n# fix option 2: pin to a cached revision (find via: git --git-dir ~/.cargo/git/db/repo-*.db log)","handlingStrategy":"validation","validationCode":"// Before building offline, verify the locked git revision is cached locally.\nuse std::process::Command;\nfn ensure_git_rev_cached(repo_url: &str, rev: &str, cargo_home: &Path) -> std::io::Result<()> {\n    let db_dir = cargo_home.join(\"git/db\");\n    let found = std::fs::read_dir(&db_dir)?.filter_map(Result::ok).any(|e| {\n        let p = e.path();\n        p.is_dir() && Command::new(\"git\")\n            .arg(\"--git-dir\").arg(&p)\n            .arg(\"cat-file\").arg(\"-t\").arg(rev)\n            .output().ok().map_or(false, |o| o.status.success())\n    });\n    if !found { panic!(\"git rev {rev} of {repo_url} not in local cache; run `cargo fetch` online first\"); }\n    Ok(())\n}","typeGuard":"fn offline_safe(lock_rev: &str, cargo_home: &std::path::Path) -> bool {\n    // returns true if lock_rev appears in any cached git db\n    std::fs::read_dir(cargo_home.join(\"git/db\")).ok()\n        .into_iter().flatten().filter_map(Result::ok)\n        .any(|e| std::process::Command::new(\"git\")\n            .arg(\"--git-dir\").arg(e.path())\n            .arg(\"cat-file\").arg(\"-t\").arg(lock_rev)\n            .output().ok().map_or(false, |o| o.status.success()))\n}","tryCatchPattern":"match git_source.fetch_db(is_submodule) {\n    Ok((db, rev)) => { /* use db */ },\n    Err(e) => {\n        let msg = e.to_string();\n        if msg.contains(\"offline mode\") {\n            // prompt user to fetch online or pin to a cached rev\n        }\n        return Err(e);\n    }\n}","preventionTips":["Always run `cargo fetch` on a networked machine before going offline.","Pin git dependencies to tags or full commit hashes that you have fetched.","Mirror `~/.cargo/git` between networked and offline hosts.","In CI, cache `~/.cargo/git` across runs."],"tags":["cargo","git","offline","network","dependency-resolution"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}