@@ -303,14 +303,6 @@ func repoFork(cmd *cobra.Command, args []string) error {
303303 s .FinalMSG = utils .Gray (fmt .Sprintf ("- %s\n " , loading ))
304304 s .Start ()
305305
306- authLogin , err := ctx .AuthLogin ()
307- if err != nil {
308- s .Stop ()
309- return fmt .Errorf ("could not determine current username: %w" , err )
310- }
311-
312- possibleFork := ghrepo .New (authLogin , toFork .RepoName ())
313-
314306 forkedRepo , err := api .ForkRepo (apiClient , toFork )
315307 if err != nil {
316308 s .Stop ()
@@ -323,11 +315,11 @@ func repoFork(cmd *cobra.Command, args []string) error {
323315 // returns the fork repo data even if it already exists -- with no change in status code or
324316 // anything. We thus check the created time to see if the repo is brand new or not; if it's not,
325317 // we assume the fork already existed and report an error.
326- created_ago := Since (forkedRepo .CreatedAt )
327- if created_ago > time .Minute {
318+ createdAgo := Since (forkedRepo .CreatedAt )
319+ if createdAgo > time .Minute {
328320 fmt .Fprintf (out , "%s %s %s\n " ,
329321 utils .Yellow ("!" ),
330- utils .Bold (ghrepo .FullName (possibleFork )),
322+ utils .Bold (ghrepo .FullName (forkedRepo )),
331323 "already exists" )
332324 } else {
333325 fmt .Fprintf (out , "%s Created fork %s\n " , greenCheck , utils .Bold (ghrepo .FullName (forkedRepo )))
@@ -338,6 +330,15 @@ func repoFork(cmd *cobra.Command, args []string) error {
338330 }
339331
340332 if inParent {
333+ remotes , err := ctx .Remotes ()
334+ if err != nil {
335+ return err
336+ }
337+ if remote , err := remotes .FindByRepo (forkedRepo .RepoOwner (), forkedRepo .RepoName ()); err == nil {
338+ fmt .Fprintf (out , "%s Using existing remote %s\n " , greenCheck , utils .Bold (remote .Name ))
339+ return nil
340+ }
341+
341342 remoteDesired := remotePref == "true"
342343 if remotePref == "prompt" {
343344 err = Confirm ("Would you like to add a remote for the fork?" , & remoteDesired )
0 commit comments