{"record":{"id":"e35d74c853924bad","repo":"nikivdev/code","slug":"failed-to-push-pr-head-to-any-remote","errorCode":null,"errorMessage":"failed to push PR head {} to any remote:\n{}","messagePattern":"failed to push PR head (.+?) to any remote:\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":8725,"sourceCode":"            return Ok(pr_head_selector_for_remote(repo_root, &remote, head));\n        }\n\n        let force_stderr = String::from_utf8_lossy(&force_output.stderr)\n            .trim()\n            .to_string();\n        failures.push(format!(\n            \"{remote}: push='{}' force='{}'{}\",\n            push_stderr,\n            force_stderr,\n            if push_stdout.is_empty() {\n                String::new()\n            } else {\n                format!(\" stdout='{}'\", push_stdout)\n            }\n        ));\n    }\n\n    bail!(\n        \"failed to push PR head {} to any remote:\\n{}\",\n        head,\n        failures.join(\"\\n\")\n    );\n}\n\nfn pr_push_remote_candidates(repo_root: &Path) -> Vec<String> {\n    let mut remotes: Vec<String> = git_capture_in(repo_root, &[\"remote\"])\n        .unwrap_or_default()\n        .lines()\n        .map(str::trim)\n        .filter(|s| !s.is_empty())\n        .map(|s| s.to_string())\n        .collect();\n\n    remotes.sort_by_key(|r| match r.as_str() {\n        \"fork\" => 0u8,\n        \"origin\" => 1u8,","sourceCodeStart":8707,"sourceCodeEnd":8743,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L8707-L8743","documentation":"Aggregated failure for the git fallback PR-head push: the tool tries pushing `<sha>:refs/heads/<head>` to each candidate remote, collecting a per-remote failure string (with stderr/stdout excerpts). If every remote attempt fails, it bails with the head name and the newline-joined list of all failures so the developer can see why each remote rejected the push.","triggerScenarios":"All remotes returned by `pr_push_remote_candidates()` fail the direct `git push <remote> <sha>:refs/heads/<head>` attempt, and the loop ends with a non-empty `failures` Vec, triggering the final bail.","commonSituations":"Fork/upstream setups where the developer lacks write access to every candidate remote; protected branch rules rejecting new refs; authentication failures (no SSH key loaded, bad credential helper); remote rejecting non-fast-forward or oversized pushes.","solutions":["Read the per-remote failure details in the message (stderr excerpts are included)","Gain write access or use the remote you can push to (e.g. your fork, not upstream)","Fix credentials: `ssh-add`, `gh auth login`, or git credential helper","Try the push manually: `git push <remote> <sha>:refs/heads/<head>` and resolve the reported rejection"],"exampleFix":"// before\nError: failed to push PR head review/pr-123 to any remote:\nremote 'origin': ! [remote rejected] (protected branch hook declined)\n// after\n$ gh auth login && git push origin <sha>:refs/heads/review/pr-123\n# or push to your fork:\n$ git remote add fork git@github.com:me/repo.git\n$ tool create-review","handlingStrategy":"retry","validationCode":"fn can_push(remote: &str) -> bool {\n    Command::new(\"git\")\n        .args([\"ls-remote\", \"--exit-code\", remote])\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}\nlet writable: Vec<_> = remotes.into_iter().filter(|r| can_push(r)).collect();\nif writable.is_empty() { eprintln!(\"no pushable remote; fix auth or add your fork\"); }","typeGuard":null,"tryCatchPattern":"let msg = e.to_string();\nfor line in msg.lines().skip(1) {\n    eprintln!(\"per-remote failure: {line}\"); // surface each remote's cause\n}\nif msg.contains(\"denied\") || msg.contains(\"auth\") {\n    eprintln!(\"run `ssh-add` / `gh auth login`, or push to a fork you own\");\n}","preventionTips":["Pre-test pushability with `git push --dry-run <remote> <refspec>`","Order remotes so the one you can definitely write to (your fork) is tried first","Keep credentials fresh (credential helper / ssh-agent) before batch pushes","Check branch-protection/permissions on every candidate remote"],"tags":["git","push","remote","auth","fallback"],"backgroundTag":"git-push-rejected","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}