{"record":{"id":"f91b2023c3664133","repo":"Hmbown/CodeWhale","slug":"refusing-to-update-existing-remote-branch-branch","errorCode":null,"errorMessage":"refusing to update existing remote branch {branch}","messagePattern":"refusing to update existing remote branch (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/dispatch_runner.rs","lineNumber":534,"sourceCode":"    )\n    .context(\"the agent patch did not apply cleanly onto the target branch\")?;\n    git(Some(&repo), &[\"rev-parse\", \"HEAD\"]).map(|out| out.trim().to_string())\n}\n\n/// Push the prepared branch. Plain push only — `--force` is never passed, so\n/// an existing branch that is not a fast-forward fails closed instead of\n/// rewriting the target's history.\nfn push_branch(repo: &Path, remote_url: &str, branch: &str) -> Result<()> {\n    let remote_url = cloud_dispatch::validate_git_remote_url(remote_url)?;\n    if cloud_dispatch::is_forge_default_branch(branch) {\n        bail!(\"refusing to push onto the forge default branch {branch}\");\n    }\n    if looks_like_network_remote(&remote_url) && cloud_dispatch::classify_url(&remote_url).is_none()\n    {\n        bail!(\"refusing to push to a non-forge remote\");\n    }\n    if remote_branch_exists(&remote_url, branch)? {\n        bail!(\"refusing to update existing remote branch {branch}\");\n    }\n    git(\n        Some(repo),\n        &[\n            \"push\",\n            \"--quiet\",\n            \"--\",\n            &remote_url,\n            &format!(\"HEAD:refs/heads/{branch}\"),\n        ],\n    )\n    .map(|_| ())\n    .context(\n        \"could not push the cloud agent branch (it may need credentials or the branch may have moved)\",\n    )\n}\n\nfn looks_like_network_remote(url: &str) -> bool {","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/dispatch_runner.rs#L516-L552","documentation":"Before pushing, push_branch checks whether the branch already exists on the remote (ls-remote). If it does, the push is refused so dispatch never overwrites someone else's or a previous job's remote branch — pushes are create-only.","triggerScenarios":"push_branch is called for a branch name that remote_branch_exists finds on the remote — e.g. re-running a job with the same generated branch name.","commonSituations":"Re-running a dispatch job after a partial failure, branch-name collisions between agents using a shared scheme, or a branch left over from an earlier task.","solutions":["Pick a fresh unique branch name (include a timestamp or job id)","Delete the existing remote branch if you own it and truly want it replaced, then retry","Check the remote (`git ls-remote --heads <url>`) before choosing the branch"],"exampleFix":"// before\nlet branch = \"codewhale/task\"; // already on remote\n// after\nlet branch = format!(\"codewhale/task-{}\", job_id);","handlingStrategy":"validation","validationCode":"let exists = remote_branch_exists(&url, &branch)?;\nif exists { branch = format!(\"{}-{}\", branch, unique_suffix()); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Include a job id or timestamp in generated branch names","Run git ls-remote before choosing a branch name","Clean up stale remote branches from prior runs"],"tags":["git","push","conflict"],"backgroundTag":"conflicting-config-options","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}