affaan-m/ECC · error · anyhow::Error
git push failed: {stderr}
Error message
git push failed: {stderr} What it means
create_draft_pr_with_gh pushes the worktree branch with `git push -u origin <branch>` before invoking `gh pr create`. A non-zero push exit re-throws git's stderr. This happens before any GitHub API call, so auth/rate-limit issues are not yet in play.
Source
Thrown at ecc2/src/worktree/mod.rs:560
anyhow::bail!("PR title cannot be empty");
}
let base_branch = options
.base_branch
.as_deref()
.map(str::trim)
.filter(|value| !value.is_empty())
.unwrap_or(&worktree.base_branch);
let push = Command::new("git")
.arg("-C")
.arg(&worktree.path)
.args(["push", "-u", "origin", &worktree.branch])
.output()
.context("Failed to push worktree branch before PR creation")?;
if !push.status.success() {
let stderr = String::from_utf8_lossy(&push.stderr);
anyhow::bail!("git push failed: {stderr}");
}
let mut command = Command::new(gh_bin);
command
.arg("pr")
.arg("create")
.arg("--draft")
.arg("--base")
.arg(base_branch)
.arg("--head")
.arg(&worktree.branch)
.arg("--title")
.arg(title)
.arg("--body")
.arg(body);
for label in options
.labels
.iter()View on GitHub (pinned to 01e15490f0)
Solutions
- Confirm `origin` exists and is reachable: `git -C <path> remote -v` and a manual `git ls-remote origin`.
- For divergent branch history, decide between rebase/merge or an explicit force-push (the library does not force-push; you must reconcile history first).
- Ensure credentials are configured (SSH key loaded, or `gh auth setup-git` for HTTPS).
- Retry once on transient network errors before surfacing the failure.
Example fix
// before
let url = create_draft_pr(&worktree, title, body)?;
// after
// pre-flight: confirm origin is reachable
let ok = Command::new("git").arg("-C").arg(&worktree.path)
.args(["ls-remote", "origin", "HEAD"]).output()?.status.success();
if !ok { anyhow::bail!("cannot reach origin; check network/auth"); }
let url = create_draft_pr(&worktree, title, body)?; Defensive patterns
Strategy: retry
Validate before calling
use std::process::Command;
fn origin_reachable(worktree: &WorktreeInfo) -> bool {
Command::new("git")
.arg("-C").arg(&worktree.path)
.args(["ls-remote", "origin", "HEAD"])
.output()
.map(|o| o.status.success())
.unwrap_or(false)
}
if !origin_reachable(&worktree) {
anyhow::bail!("origin is not reachable; check network and credentials");
}
let url = create_draft_pr(&worktree, title, body)?; Try / catch
fn create_pr_with_retry(w: &WorktreeInfo, title: &str, body: &str, attempts: u8) -> anyhow::Result<String> {
let mut last = None;
for _ in 0..attempts {
match create_draft_pr(w, title, body) {
Ok(url) => return Ok(url),
Err(e) => {
let m = format!("{e:#}");
if m.contains("git push failed") && (m.contains("timed out") || m.contains("Connection")) {
last = Some(e); // transient — retry
continue;
}
return Err(e); // non-transient — surface
}
}
}
Err(last.unwrap())
} Prevention
- Run `gh auth setup-git` once so HTTPS credentials are wired into git itself.
- Confirm `git remote -v` shows the expected push URL before the first PR.
- Rebase onto the latest remote base before pushing to avoid non-fast-forward rejections (the library does not force-push).
- Retry transient network errors once before surfacing.
When it happens
Trigger: No network/offline; no `origin` remote or wrong push URL; branch already exists on the remote with divergent history and `push -u` is non-forcing; SSH key/credential helper missing or rejected; remote rejected by a pre-receive hook (branch protection, signed-commits policy).
Common situations: First push of a new feature branch over a flaky connection; SSH agent not running; branch was force-pushed by someone else; protected branch rules reject the push; corporate proxy blocks the git protocol.
Related errors
- git worktree add failed: {stderr}
- git status failed: {stderr}
- git add failed for {path}: {stderr}
- git reset failed for {path}: {stderr}
- git restore failed for {}: {stderr}
AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13).
Data as JSON: /api/errors/3e924eef7408af28.
Report an issue: GitHub.