{"record":{"id":"36dc5c8fedd937e5","repo":"rust-lang/cargo","slug":"cannot-specify-a-git-url-url-with-a-version","errorCode":null,"errorMessage":"cannot specify a git URL (`{url}`) with a version (`{v}`).","messagePattern":"cannot specify a git URL \\(`(.+?)`\\) with a version \\(`(.+?)`\\)\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_add/mod.rs","lineNumber":373,"sourceCode":"        .as_deref()\n        .map(CrateSpec::resolve)\n        .transpose()?;\n    let mut selected_dep = if let Some(url) = &arg.git {\n        let mut src = GitSource::new(url);\n        if let Some(branch) = &arg.branch {\n            src = src.set_branch(branch);\n        }\n        if let Some(tag) = &arg.tag {\n            src = src.set_tag(tag);\n        }\n        if let Some(rev) = &arg.rev {\n            src = src.set_rev(rev);\n        }\n\n        let selected = if let Some(crate_spec) = &crate_spec {\n            if let Some(v) = crate_spec.version_req() {\n                // crate specifier includes a version (e.g. `docopt@0.8`)\n                anyhow::bail!(\"cannot specify a git URL (`{url}`) with a version (`{v}`).\");\n            }\n            let dependency = crate_spec.to_dependency()?.set_source(src);\n            let selected = select_package(&dependency, gctx, registry)?;\n            if dependency.name != selected.name {\n                gctx.shell().warn(format!(\n                    \"translating `{}` to `{}`\",\n                    dependency.name, selected.name,\n                ))?;\n            }\n            selected\n        } else {\n            let source = crate::sources::GitSource::new(src.source_id()?, gctx)?;\n            let packages = source.read_packages()?;\n            let package = infer_package_for_git_source(packages, &src)?;\n            Dependency::from(package.summary())\n        };\n        selected\n    } else if let Some(raw_path) = &arg.path {","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/ops/cargo_add/mod.rs#L355-L391","documentation":"Thrown by cargo add when a dependency is specified with both a version requirement (via crate@version syntax, e.g. foo@1.0) and a --git URL. These are mutually exclusive source specifications: a git source pins the version to what exists in the repository, so an explicit version requirement is meaningless.","triggerScenarios":"Running `cargo add foo@1.0 --git https://github.com/user/foo` where both the @version suffix and --git flag are present.","commonSituations":"Copy-pasting a version from one command and a git URL from another. Forgetting to remove the version specifier when switching from registry to git source. Following outdated examples.","solutions":["Remove the version suffix from the crate spec: `cargo add foo --git https://github.com/user/foo`","Or remove --git if you want a registry version: `cargo add foo@1.0`"],"exampleFix":"# before\ncargo add foo@1.0 --git https://github.com/user/foo\n# error: cannot specify a git URL with a version\n\n# after — omit version when using --git\ncargo add foo --git https://github.com/user/foo","handlingStrategy":"validation","validationCode":"// Validate that version and git are not both specified\nfn validate_add_args(crate_spec: &str, git_url: Option<&str>) -> Result<(), String> {\n    let has_version = crate_spec.contains('@');\n    if has_version && git_url.is_some() {\n        return Err(\"cannot specify a git URL with a version; remove one\".into());\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When using --git, omit the @version suffix from the crate name","When specifying a version, omit the --git flag","Review the cargo add command before running to ensure only one source is specified"],"tags":["cargo-add","git","dependency","conflict"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}