affaan-m/ECC · error

git remote get-url origin failed

Error message

git remote get-url origin failed: {stderr}

What it means

git_remote_origin_url runs `git remote get-url origin` on the repo root to build a GitHub compare URL. This error is raised when git exits nonzero — normally because the repository has no remote named 'origin' — with git's stderr included in the message.

Solutions

  1. Add or fix the origin remote: `git remote add origin <url>` or rename the existing remote to origin.
  2. Run `git remote -v` in the repo root to see what remotes exist.
  3. If origin legitimately may be absent, skip compare-URL generation and handle the error instead of failing the whole flow.
  4. Confirm the repo_root path passed in is the actual git checkout.

Example fix

// before
let url = github_compare_url(&wt)?; // fails when origin missing
// after
match github_compare_url(&wt) {
    Ok(url) => println!("{url}"),
    Err(_) => eprintln!("no origin remote; compare URL unavailable"),
}
Defensive patterns

Strategy: fallback

Validate before calling

fn has_origin(root: &Path) -> bool {
    Command::new("git").arg(root).args(["remote", "get-url", "origin"])
        .output().map(|o| o.status.success()).unwrap_or(false)
}

Try / catch

match github_compare_url(&wt) {
    Ok(url) => use(url),
    Err(_) => eprintln!("compare URL unavailable: no origin remote"),
}

Prevention

When it happens

Trigger: Calling github_compare_url on a repo where origin was never added, was renamed, or the path is not a git repository.

Common situations: Locally cloned repos added as remotes under a different name (e.g. 'upstream'); repos initialized without a remote; bare repos reorganized after cloning; CI checkouts using a remote alias.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/634f7869c5122f42. Report an issue: GitHub.

Appendix: source

Thrown at ecc2/src/worktree/mod.rs:613

        .context("Failed to create draft PR with gh")?;
    if !output.status.success() {
        let stderr = String::from_utf8_lossy(&output.stderr);
        anyhow::bail!("gh pr create failed: {stderr}");
    }

    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}

fn git_remote_origin_url(repo_root: &Path) -> Result<String> {
    let output = Command::new("git")
        .arg("-C")
        .arg(repo_root)
        .args(["remote", "get-url", "origin"])
        .output()
        .context("Failed to resolve git origin remote")?;
    if !output.status.success() {
        let stderr = String::from_utf8_lossy(&output.stderr);
        anyhow::bail!("git remote get-url origin failed: {stderr}");
    }

    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}

fn github_repo_web_url(origin: &str) -> Option<String> {
    let trimmed = origin.trim().trim_end_matches(".git");
    if trimmed.is_empty() {
        return None;
    }

    if let Some(rest) = trimmed.strip_prefix("git@") {
        let (host, path) = rest.split_once(':')?;
        return Some(format!("https://{host}/{}", path.trim_start_matches('/')));
    }

    if let Some(rest) = trimmed.strip_prefix("ssh://") {
        return parse_httpish_remote(rest);

View on GitHub (pinned to 8321021c54)