{"record":{"id":"5911864f432dcb9b","repo":"mislav/hub","slug":"error-creating-fork-s-already-exists-on-s","errorCode":null,"errorMessage":"Error creating fork: %s already exists on %s","messagePattern":"Error creating fork: (.+?) already exists on (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/fork.go","lineNumber":85,"sourceCode":"\t} else {\n\t\tnewRemoteName = forkProject.Owner\n\t}\n\n\tclient := github.NewClient(project.Host)\n\texistingRepo, err := client.Repository(forkProject)\n\tif err == nil {\n\t\texistingProject, err := github.NewProjectFromRepo(existingRepo)\n\t\tif err == nil && !existingProject.SameAs(forkProject) {\n\t\t\texistingRepo = nil\n\t\t}\n\t}\n\tif err == nil && existingRepo != nil {\n\t\tvar parentURL *github.URL\n\t\tif parent := existingRepo.Parent; parent != nil {\n\t\t\tparentURL, _ = github.ParseURL(parent.HTMLURL)\n\t\t}\n\t\tif parentURL == nil || !project.SameAs(parentURL.Project) {\n\t\t\terr = fmt.Errorf(\"Error creating fork: %s already exists on %s\",\n\t\t\t\tforkProject, forkProject.Host)\n\t\t\tutils.Check(err)\n\t\t}\n\t} else {\n\t\tif !args.Noop {\n\t\t\tnewRepo, err := client.ForkRepository(project, params)\n\t\t\tutils.Check(err)\n\t\t\tforkProject.Owner = newRepo.Owner.Login\n\t\t\tforkProject.Name = newRepo.Name\n\t\t}\n\t}\n\n\targs.NoForward()\n\tif !args.Flag.Bool(\"--no-remote\") {\n\t\toriginURL := project.GitURL(\"\", \"\", false)\n\t\turl := forkProject.GitURL(\"\", \"\", true)\n\n\t\t// Check to see if the remote already exists.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/mislav/hub/blob/5c547ed804368763064e51f3990851e267e88edd/commands/fork.go#L67-L103","documentation":"gh's `fork` command found that a repo with the fork name already exists on the target host, but its recorded parent does not match the repo you asked to fork (or the parent URL could not be parsed). The command refuses to proceed because the existing repo is not actually a fork of the requested project, so forking would be misleading. It is a pre-flight consistency check in `fork` before any fork API call is made.","triggerScenarios":"Running `gh repo fork owner/name` (or `git fork ...`) where `client.Repository(project)` returns an existing repo whose `Parent.HTMLURL` project differs from the source project, or whose Parent is nil/unparseable, while no `--noop` flag path is taken.","commonSituations":"A repo with the same name already exists under your account but was created independently (not forked); you forked the repo long ago and the upstream was renamed/transferred so the recorded Parent no longer matches; GitHub Enterprise vs github.com host mismatch causing project comparison to fail.","solutions":["Delete or rename the existing same-named repo (via web UI or `gh delete-repo`) and retry the fork.","Verify the existing repo is actually a fork of the intended source; if it is, no new fork is needed — add it as a remote instead.","Check you are targeting the correct host (github.com vs Enterprise); a wrong host can make the parent comparison fail.","If the upstream was renamed/transferred, update your local remote URLs and retry."],"exampleFix":"// before\ngit fork owner/name   # fails: fork-name already exists but isn't a fork of owner/name\n// after\n# delete the stale repo first, then\ngit fork owner/name","handlingStrategy":"validation","validationCode":"// Check the target repo state before forking\nexisting, _ := client.Repository(targetProject)\nif existing != nil {\n    isForkOfSource := existing.Parent != nil &&\n        parentProjectOf(existing.Parent) == sourceProject\n    if !isForkOfSource {\n        fmt.Printf(\"%s already exists and is not a fork of %s; delete or rename it first\\n\",\n            targetProject, sourceProject)\n        os.Exit(1)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check whether a same-named repo already exists before running fork.","Keep forks as actual forks instead of re-creating repos with the same name.","Keep local remote URLs in sync when upstream repos are renamed or transferred.","Verify the correct host (github.com vs Enterprise) before forking."],"tags":["fork","name-conflict","github-api"],"backgroundTag":"repo-name-already-exists","analyzedSha":"5c547ed804368763064e51f3990851e267e88edd","analyzedAt":"2026-09-01T03:34:15.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}