{"record":{"id":"627c3fdb0241004b","repo":"mislav/hub","slug":"repository-s-already-exists-and-is-public","errorCode":null,"errorMessage":"Repository '%s' already exists and is public","messagePattern":"Repository '(.+?)' already exists and is public","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/create.go","lineNumber":105,"sourceCode":"\n\towner := host.User\n\tif strings.Contains(newRepoName, \"/\") {\n\t\tsplit := strings.SplitN(newRepoName, \"/\", 2)\n\t\towner = split[0]\n\t\tnewRepoName = split[1]\n\t}\n\n\tproject := github.NewProject(owner, newRepoName, host.Host)\n\tgh := github.NewClient(project.Host)\n\n\tflagCreatePrivate := args.Flag.Bool(\"--private\")\n\n\trepo, err := gh.Repository(project)\n\tif err == nil {\n\t\tfoundProject := github.NewProject(repo.FullName, \"\", project.Host)\n\t\tif foundProject.SameAs(project) {\n\t\t\tif !repo.Private && flagCreatePrivate {\n\t\t\t\terr = fmt.Errorf(\"Repository '%s' already exists and is public\", repo.FullName)\n\t\t\t\tutils.Check(err)\n\t\t\t} else {\n\t\t\t\tui.Errorln(\"Existing repository detected\")\n\t\t\t\tproject = foundProject\n\t\t\t}\n\t\t} else {\n\t\t\trepo = nil\n\t\t}\n\t} else {\n\t\trepo = nil\n\t}\n\n\tif repo == nil {\n\t\tif !args.Noop {\n\t\t\tflagCreateDescription := args.Flag.Value(\"--description\")\n\t\t\tflagCreateHomepage := args.Flag.Value(\"--homepage\")\n\t\t\trepo, err := gh.CreateRepository(project, flagCreateDescription, flagCreateHomepage, flagCreatePrivate)\n\t\t\tutils.Check(err)","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/create.go#L87-L123","documentation":"In commands/create.go create, when gh.Repository(project) succeeds the repo already exists on the host. If it is the same project and is public while the user requested a private repo (flagCreatePrivate), the command fails with \"Repository '%s' already exists and is public\" because privacy cannot be retroactively applied this way.","triggerScenarios":"Running `hub create -p` (private) for a repository name that already exists on the host as a public repo whose FullName maps to the same project (foundProject.SameAs(project)).","commonSituations":"Re-running `hub create -p` after an earlier public create; name collision with an existing public repo under your account/org; scripted create that assumed fresh names; switching from public to private expectations mid-setup.","solutions":["If privacy is required, change visibility in GitHub Settings (General -> Danger Zone -> Change visibility) or via API, then continue.","Delete the existing public repo (if safe) and rerun `hub create -p`.","Choose a different repository name that doesn't exist.","If the existing public repo is fine, rerun without `-p` and let hub reuse it (it prints \"Existing repository detected\")."],"exampleFix":"// before\nhub create -p   // Repository 'user/proj' already exists and is public\n// after\n# either reuse it:\nhub create\n# or flip visibility first via GitHub settings, then:\nhub create -p","handlingStrategy":"validation","validationCode":"// check existing repo visibility before requesting private create\nrepo, err := gh.Repository(project)\nif err == nil && !repo.Private && flagCreatePrivate {\n    return fmt.Errorf(\"%s exists and is public; change visibility or pick another name\", repo.FullName)\n}","typeGuard":null,"tryCatchPattern":"repo, err := gh.Repository(project)\nif err == nil {\n    if !repo.Private && flagCreatePrivate {\n        fmt.Fprintln(os.Stderr, \"repo exists as public; adjusting visibility via API\")\n        // handle: change visibility or choose new name\n    }\n}","preventionTips":["Probe the API for the repo's existence/visibility before create scripts run","Use unique repo names (timestamp/suffix) in automation","Decide public vs private up front and don't flip with -p on retries","Rerun without -p if reusing the existing repo is acceptable"],"tags":["github","cli","repository","permissions"],"backgroundTag":"repository-already-exists","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}