nikivdev/code · error
failed to create repo via gh (is it installed/authenticated?
Error message
failed to create repo via gh (is it installed/authenticated?)
What it means
Raised by ensure_github_repo_exists in src/push.rs when the `gh repo create <owner>/<repo> --private` subprocess exits non-zero (the `gh repo view` pre-check already showed the repo does not exist or is not visible). It indicates the GitHub CLI failed to create the mirror repository, most often because gh is not installed, not authenticated, or lacks permission.
Source
Thrown at src/push.rs:303
.stdout(Stdio::null())
.stderr(Stdio::null())
.status();
if matches!(view, Ok(s) if s.success()) {
return Ok(());
}
println!("==> Creating GitHub repo {} (private)...", full_name);
let status = Command::new("gh")
.args(["repo", "create", &full_name, "--private", "--confirm"])
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status();
match status {
Ok(s) if s.success() => Ok(()),
Ok(_) => bail!("failed to create repo via gh (is it installed/authenticated?)"),
Err(err) => Err(err).context("failed to run gh"),
}
}
pub(crate) fn normalize_git_url(url: &str) -> String {
let url = url.trim();
let url = if url.starts_with("git@github.com:") {
url.replace("git@github.com:", "github.com/")
} else if url.starts_with("https://github.com/") {
url.replace("https://github.com/", "github.com/")
} else {
url.to_string()
};
url.trim_end_matches(".git").to_lowercase()
}
fn git_root() -> Result<PathBuf> {
let output = Command::new("git")View on GitHub (pinned to a747e741ae)
Solutions
- Install the GitHub CLI and authenticate with `gh auth login`, then verify with `gh auth status`
- Run `gh repo create owner/repo --private` manually to see the exact underlying error
- Confirm you have permission to create repos under the target owner/org, or create the repo manually in GitHub and re-run the push
Example fix
// before: unauthenticated gh fails $ f push failed to create repo via gh (is it installed/authenticated?) // after $ gh auth login $ f push
Defensive patterns
Strategy: validation
Validate before calling
let ok = std::process::Command::new("gh")
.args(["auth", "status"])
.status()
.map(|s| s.success())
.unwrap_or(false);
if !ok { eprintln!("install gh and run `gh auth login` first"); } Try / catch
match result {
Err(e) if e.to_string().contains("failed to create repo via gh") => {
eprintln!("run `gh auth status` and `gh repo create` manually for details");
}
Err(e) => return Err(e),
Ok(v) => Ok(v),
} Prevention
- Install gh and run `gh auth login` before first push
- Verify `gh repo view owner/repo` works beforehand
- Ensure your account has repo-creation rights in the target org
When it happens
Trigger: The `gh repo view owner/repo` check fails (repo absent or gh unauthenticated), then `gh repo create owner/repo --private --confirm` runs and returns a non-zero exit status.
Common situations: gh CLI not installed or not on PATH for the spawned process; `gh auth login` never run or token expired; the authenticated account lacks rights to create repos in the target owner (org); gh version where `--confirm` was removed/deprecated causing argument errors.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- gh {} failed: {}
- failed to create private repo {}
- `gh` is installed but not working
- unable to determine GitHub repo (origin URL not GitHub, and
- failed to determine PR URL after creation (gh output had no
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/6478a3648ef63961.
Report an issue: GitHub.