nikivdev/code · error

No git remotes configured; cannot push PR head {}

Error message

No git remotes configured; cannot push PR head {}

What it means

When the git-based fallback path pushes the PR head commit directly to a branch ref (`<sha>:refs/heads/<head>`), it needs at least one configured git remote. `pr_push_remote_candidates()` returns candidates (favoring writable remotes in fork/upstream setups), and if that list is empty the tool bails immediately, since there is nowhere to push.

Source

Thrown at src/commit.rs:8679

        }
        let jj_error = jj_result.unwrap_err().to_string();
        let concise = jj_error
            .lines()
            .map(str::trim)
            .find(|line| !line.is_empty())
            .unwrap_or("jj failed");
        eprintln!(
            "⚠️  jj bookmark push failed ({}). Falling back to git branch push for PR head.",
            concise
        );
    }

    // Fallback: push commit directly to a branch ref.
    // Try likely writable remotes first to support fork/upstream setups.
    let head_refspec = format!("{}:refs/heads/{}", commit_sha, head);
    let remotes = pr_push_remote_candidates(repo_root);
    if remotes.is_empty() {
        bail!("No git remotes configured; cannot push PR head {}", head);
    }

    let mut failures: Vec<String> = Vec::new();
    for remote in remotes {
        let push_output = Command::new("git")
            .current_dir(repo_root)
            .args(["push", "-u", &remote, &head_refspec])
            .output()
            .with_context(|| format!("failed to run git push for remote {remote}"))?;
        if push_output.status.success() {
            return Ok(pr_head_selector_for_remote(repo_root, &remote, head));
        }

        let push_stderr = String::from_utf8_lossy(&push_output.stderr)
            .trim()
            .to_string();
        let push_stdout = String::from_utf8_lossy(&push_output.stdout)
            .trim()

View on GitHub (pinned to a747e741ae)

Solutions

  1. Add a remote: `git remote add origin git@github.com:owner/repo.git`
  2. Verify with `git remote -v` that at least one remote exists and is writable
  3. Re-run the operation from the correct repository directory
  4. If using forks, add both origin and upstream remotes

Example fix

// before
$ git remote -v
(empty)
Error: No git remotes configured; cannot push PR head review/pr-123
// after
$ git remote add origin git@github.com:owner/repo.git
$ tool create-review
Defensive patterns

Strategy: validation

Validate before calling

let remotes = String::from_utf8_lossy(
    &Command::new("git").args(["remote"]).output()?.stdout);
if remotes.trim().is_empty() {
    return Err(anyhow!("add a remote first: git remote add origin <url>"));
}

Prevention

When it happens

Trigger: Fallback direct-push path is taken and `pr_push_remote_candidates(repo_root)` returns an empty Vec — i.e. `git remote` lists no remotes in the repository.

Common situations: Fresh local clone-less repo (`git init` only) with no remote added; remotes removed during repo migration; running the tool in a bare or scratch checkout; typos in remote configuration scripts.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/76b4802c75a82d5d. Report an issue: GitHub.