nikivdev/code · error

Failed to create repository

Error message

Failed to create repository

What it means

run_github creates the repository by invoking `gh repo create ...`; the command runs but exits with a non-zero status, so the tool bails with this generic failure message. The underlying cause (name conflict, auth, network) is printed by `gh` itself to stderr before this error is raised.

Source

Thrown at src/publish.rs:365

        "create".to_string(),
        repo_name.clone(),
        format!("--{}", visibility),
        "--source=.".to_string(),
        "--push".to_string(),
    ];

    if let Some(desc) = opts.description {
        args.push("--description".to_string());
        args.push(desc);
    }

    let create_result = Command::new("gh")
        .args(&args)
        .status()
        .context("failed to create repository")?;

    if !create_result.success() {
        bail!("Failed to create repository");
    }

    println!();
    println!("✓ Published to https://github.com/{}", full_name);

    Ok(())
}

const MAX_GITEDIT_FILE_BYTES: u64 = 512 * 1024;
const MAX_GITEDIT_TOTAL_BYTES: u64 = 8 * 1024 * 1024;
const MAX_GITEDIT_FILES: usize = 4000;

#[derive(Serialize)]
#[serde(rename_all = "snake_case")]
struct RepoSnapshot {
    repo: RepoMeta,
    tree: Vec<RepoTreeEntry>,
    files: Vec<RepoFileEntry>,

View on GitHub (pinned to a747e741ae)

Solutions

  1. Read the stderr lines printed by `gh repo create` just above this error for the real cause
  2. If the repo already exists, skip creation (the publish flow detects existing repos when it can check) or pick a new name with --name
  3. Run `gh auth status` / `gh auth refresh -s repo` to ensure the token has repo-creation scopes
  4. Check you can create repos manually: `gh repo create test-repo --private`
  5. If an org policy blocks creation, create the repo on github.com first and publish with --url

Example fix

// before: failing because repo exists
f publish --repo myapp
// after: reuse existing repo via --url
f publish --url git@github.com:myuser/myapp.git
Defensive patterns

Strategy: try-catch

Validate before calling

let check = std::process::Command::new("gh")
    .args(["repo", "view", &format!("{}/{}", owner, name), "--json", "name"])
    .output()?;
if check.status.success() {
    eprintln!("repo already exists; skipping creation");
    return Ok(()); // or reuse it instead of calling create
}

Try / catch

match run_github(opts) {
    Err(e) if e.to_string().contains("Failed to create repository") => {
        eprintln!("gh repo create failed; check stderr above — name conflict, token scope, or network");
    }
    other => other?,
}

Prevention

When it happens

Trigger: `gh repo create <owner>/<name> --<visibility> ...` returns a failing exit status: repository name already exists under the owner, the token lacks `repo`/`create repo` scope, rate limiting, or network failure.

Common situations: Re-publishing an existing project with the same folder name; organization accounts that forbid member repo creation; expired GitHub token lacking repo scope; `gh repo create` syntax changes across gh versions.

Related errors


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