{"record":{"id":"3e924eef7408af28","repo":"affaan-m/ECC","slug":"git-push-failed-stderr","errorCode":null,"errorMessage":"git push failed: {stderr}","messagePattern":"git push failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":560,"sourceCode":"        anyhow::bail!(\"PR title cannot be empty\");\n    }\n\n    let base_branch = options\n        .base_branch\n        .as_deref()\n        .map(str::trim)\n        .filter(|value| !value.is_empty())\n        .unwrap_or(&worktree.base_branch);\n\n    let push = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"push\", \"-u\", \"origin\", &worktree.branch])\n        .output()\n        .context(\"Failed to push worktree branch before PR creation\")?;\n    if !push.status.success() {\n        let stderr = String::from_utf8_lossy(&push.stderr);\n        anyhow::bail!(\"git push failed: {stderr}\");\n    }\n\n    let mut command = Command::new(gh_bin);\n    command\n        .arg(\"pr\")\n        .arg(\"create\")\n        .arg(\"--draft\")\n        .arg(\"--base\")\n        .arg(base_branch)\n        .arg(\"--head\")\n        .arg(&worktree.branch)\n        .arg(\"--title\")\n        .arg(title)\n        .arg(\"--body\")\n        .arg(body);\n    for label in options\n        .labels\n        .iter()","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L542-L578","documentation":"Before creating a PR, create_draft_pr_with_gh pushes the worktree branch to origin with `git push -u origin <branch>`. This error is raised when the push exits nonzero; git's stderr (e.g. rejected non-fast-forward, auth failure) is embedded in the message.","triggerScenarios":"Calling create_draft_pr with a branch that diverged from its upstream, lacks push permission to origin, is protected by branch rules, or when the remote is unreachable / credentials are missing.","commonSituations":"SSH key or credential helper not configured in CI; branch rejected because remote has newer commits (`! [rejected] ... fetch first`); pushing to a repo where the user has read-only access; offline environment.","solutions":["Read the embedded stderr — it distinguishes rejection, auth, and network failures.","`git fetch origin` then rebase or merge the branch if the push was rejected as non-fast-forward.","Configure credentials (ssh key, gh auth login, or credential helper) for the environment running the push.","Verify push permission on origin: `git push --dry-run origin <branch>`.","Check branch protection rules if the remote explicitly rejects the ref update."],"exampleFix":"// before\ncreate_draft_pr(&wt, \"title\", \"body\")?; // fails: diverged branch\n// after\nCommand::new(\"git\").arg(\"-C\").arg(&wt.path).args([\"pull\",\"--rebase\",\"origin\",&wt.branch]).status()?;\ncreate_draft_pr(&wt, \"title\", \"body\")?;","handlingStrategy":"retry","validationCode":"let dry = Command::new(\"git\").arg(&wt.path).args([\"push\", \"--dry-run\", \"origin\", &wt.branch]).output()?;\nif !dry.status.success() { eprintln!(\"push would fail: {}\", String::from_utf8_lossy(&dry.stderr)); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = create_draft_pr(&wt, title, body) {\n    let msg = e.to_string();\n    if msg.contains(\"fetch first\") || msg.contains(\"rejected\") {\n        // fetch + rebase, then retry once\n    } else if msg.contains(\"Permission\") || msg.contains(\"auth\") {\n        eprintln!(\"configure credentials for origin\");\n    }\n}","preventionTips":["Set up SSH keys or a credential helper in CI","Fetch and rebase the branch before creating PRs","Use `git push --dry-run` as a precheck","Check remote write permissions for the token"],"tags":["git","network","push"],"backgroundTag":"git-command-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}