nikivdev/code · error

unable to determine GitHub repo (origin URL not GitHub, and

Error message

unable to determine GitHub repo (origin URL not GitHub, and `gh repo view` returned empty)

What it means

When determining which GitHub repository the current directory belongs to, the tool first tries parsing the origin URL; if that is not a GitHub remote it falls back to `gh repo view --json nameWithOwner`. This error is raised when both strategies fail: the origin URL isn't a GitHub URL and `gh repo view` returned an empty string. The tool cannot proceed without knowing the target repo.

Source

Thrown at src/commit.rs:8566

        }
    }

    // Fallback: ask `gh` (works for GitHub Enterprise too if authenticated).
    let repo = gh_capture_in(
        repo_root,
        &[
            "repo",
            "view",
            "--json",
            "nameWithOwner",
            "-q",
            ".nameWithOwner",
        ],
    )
    .context("failed to resolve GitHub repo for current directory")?;
    let repo = repo.trim();
    if repo.is_empty() {
        bail!(
            "unable to determine GitHub repo (origin URL not GitHub, and `gh repo view` returned empty)"
        );
    }
    Ok(repo.to_string())
}

fn sanitize_ref_component(input: &str) -> String {
    let mut out = String::new();
    let mut last_sep = false;
    for ch in input.chars() {
        if ch.is_ascii_alphanumeric() || ch == '-' || ch == '_' || ch == '.' {
            out.push(ch);
            last_sep = false;
        } else if !last_sep {
            out.push('-');
            last_sep = true;
        }
    }

View on GitHub (pinned to a747e741ae)

Solutions

  1. Set the origin to a GitHub URL: `git remote set-url origin git@github.com:owner/repo.git`
  2. Or make gh resolve it: `gh repo view` manually after `gh auth login`
  3. Run the tool from inside the intended git repository working tree
  4. Add explicit repo configuration to the tool if it supports specifying owner/repo

Example fix

// before
$ git remote -v
origin  https://gitlab.example.com/team/repo.git
Error: unable to determine GitHub repo ...
// after
$ git remote set-url origin https://github.com/owner/repo.git
$ tool create-review  # resolves repo successfully
Defensive patterns

Strategy: validation

Validate before calling

let url = git_remote_url("origin").unwrap_or_default();
let is_github = url.contains("github.com");
let gh_repo = Command::new("gh")
    .args(["repo", "view", "--json", "nameWithOwner",
           "--jq", ".nameWithOwner"])
    .output()?;
if !is_github && gh_repo.stdout.trim().is_empty() {
    return Err(anyhow!("set a GitHub origin or authenticate gh first"));
}

Try / catch

if let Err(e) = result {
    if e.to_string().contains("unable to determine GitHub repo") {
        eprintln!("fix `git remote set-url origin <github url>` or `gh auth login`");
    }
    return Err(e);
}

Prevention

When it happens

Trigger: `resolve_github_repo()` gets an empty trimmed result from `gh repo view --json owner.name --jq .nameWithOwner`, i.e. origin is not a GitHub URL AND gh cannot infer the repo from the directory.

Common situations: Repo whose origin points to GitLab/Bitbucket/self-hosted git; detached directory with no remote; gh not authenticated in a way that lets it resolve `repo view` without a remote; running from a subdirectory of a non-git folder.

Related errors


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