{"record":{"id":"272c3d8e36a77d75","repo":"nikivdev/code","slug":"remote-already-points-to-refusing-to-overw","errorCode":null,"errorMessage":"remote '{}' already points to {}\nrefusing to overwrite without --force\n(target would be {})","messagePattern":"remote '(.+?)' already points to (.+?)\nrefusing to overwrite without --force\n\\(target would be (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/push.rs","lineNumber":266,"sourceCode":"        .map(|s| s.trim().to_string())\n        .filter(|s| !s.is_empty());\n\n    if let Some(existing) = existing {\n        if normalize_git_url(&existing) == normalize_git_url(target_url) {\n            return Ok(());\n        }\n\n        // Safe override when the remote points at upstream (read-only clone).\n        let is_upstream = upstream_url\n            .map(|u| normalize_git_url(u) == normalize_git_url(&existing))\n            .unwrap_or(false);\n        if is_upstream || force {\n            println!(\"==> Updating remote {} url...\", remote);\n            git_run_in(repo_root, &[\"remote\", \"set-url\", remote, target_url])?;\n            return Ok(());\n        }\n\n        bail!(\n            \"remote '{}' already points to {}\\nrefusing to overwrite without --force\\n(target would be {})\",\n            remote,\n            existing,\n            target_url\n        );\n    }\n\n    println!(\"==> Adding remote {}...\", remote);\n    git_run_in(repo_root, &[\"remote\", \"add\", remote, target_url])?;\n    Ok(())\n}\n\npub(crate) fn ensure_github_repo_exists(owner: &str, repo: &str) -> Result<()> {\n    let full_name = format!(\"{}/{}\", owner.trim(), repo.trim());\n\n    let view = Command::new(\"gh\")\n        .args([\"repo\", \"view\", &full_name])\n        .stdin(Stdio::null())","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/push.rs#L248-L284","documentation":"This error is raised by ensure_remote_points_to_target in src/push.rs when a git remote already exists with a URL that differs from the target URL the mirror-push flow wants to use, and the existing URL is not the known upstream clone URL. The tool refuses to silently repoint an existing remote because doing so could break a user's deliberate remote configuration; it demands an explicit --force.","triggerScenarios":"Running the mirror push when the named remote (e.g. 'origin' or a Flow remote) exists but points to a URL different from the computed target URL, the existing URL does not normalize-match the upstream URL, and no --force flag was passed.","commonSituations":"The repo was cloned from upstream and the remote was manually repointed to a fork; the remote URL was edited by hand or by another tool; the target repo was renamed/moved on GitHub so the target URL changed; mixed SSH vs HTTPS URLs that do not normalize to the same value.","solutions":["Re-run the command with --force to allow overwriting the remote URL","Verify the remote URL with `git remote get-url <remote>` and confirm which URL is correct; update it manually with `git remote set-url <remote> <url>`","If the existing remote should stay as-is, remove it (`git remote remove <remote>`) or add the target under a different remote name"],"exampleFix":"// before: remote points elsewhere, push fails\n$ f push\nremote 'origin' already points to https://github.com/old/repo.git\nrefusing to overwrite without --force\n// after\n$ f push --force","handlingStrategy":"validation","validationCode":"let existing = std::process::Command::new(\"git\").args([\"remote\", \"get-url\", remote]).output()?;\nlet mismatch = existing.status.success()\n    && normalize(existing.stdout_str()) != normalize(target_url);\nif mismatch { eprintln!(\"remote {remote} differs from target; pass --force to overwrite\"); }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"refusing to overwrite without --force\") => {\n        // surface a prompt or auto-retry with force\n    }\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Check `git remote -v` before running mirror push","Use --force deliberately only when you know the remote should be repointed","Keep remote URLs in sync with the upstream/fork layout"],"tags":["git","remote","config-conflict"],"backgroundTag":"git-remote-url-conflict","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}