{"record":{"id":"bb658139803e4065","repo":"argoproj/argo-workflows","slug":"failed-to-create-remote-q-w","errorCode":null,"errorMessage":"failed to create remote %q: %w","messagePattern":"failed to create remote %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/artifacts/git/git.go","lineNumber":141,"sourceCode":"\t\tInsecureSkipTLS: g.InsecureSkipTLS,\n\t}\n\tif a.SingleBranch && a.Branch == \"\" {\n\t\treturn errors.New(\"single branch mode without a branch specified\")\n\t}\n\tif a.SingleBranch {\n\t\tcloneOptions.ReferenceName = plumbing.NewBranchReferenceName(a.Branch)\n\t}\n\n\tr, err := git.PlainClone(path, false, cloneOptions)\n\tif errors.Is(err, transport.ErrEmptyRemoteRepository) {\n\t\tlogging.RequireLoggerFromContext(ctx).Info(ctx, \"Cloned an empty repository\")\n\t\tvar initErr error\n\t\tr, initErr = git.PlainInit(path, false)\n\t\tif initErr != nil {\n\t\t\treturn fmt.Errorf(\"failed to plain init: %w\", initErr)\n\t\t}\n\t\tif _, remoteErr := r.CreateRemote(&config.RemoteConfig{Name: git.DefaultRemoteName, URLs: []string{a.Repo}}); remoteErr != nil {\n\t\t\treturn fmt.Errorf(\"failed to create remote %q: %w\", a.Repo, remoteErr)\n\t\t}\n\t\tbranchName := a.Revision\n\t\tif branchName == \"\" {\n\t\t\tbranchName = \"master\"\n\t\t}\n\t\tif err = r.CreateBranch(&config.Branch{Name: branchName, Remote: git.DefaultRemoteName, Merge: plumbing.Master}); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create branch %q: %w\", branchName, err)\n\t\t}\n\t\treturn nil\n\t} else if err != nil {\n\t\treturn fmt.Errorf(\"failed to clone %q: %w\", a.Repo, err)\n\t}\n\tif len(a.Fetch) > 0 {\n\t\trefSpecs := make([]config.RefSpec, len(a.Fetch))\n\t\tfor i, spec := range a.Fetch {\n\t\t\trefSpecs[i] = config.RefSpec(spec)\n\t\t}\n\t\topts := &git.FetchOptions{Auth: auth, RefSpecs: refSpecs, Depth: depth, InsecureSkipTLS: g.InsecureSkipTLS}","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/artifacts/git/git.go#L123-L159","documentation":"This error comes from workflow/artifacts/git/git.go:141 when the git artifact driver handles an empty remote repository. After PlainInit succeeds, the driver calls r.CreateRemote(&config.RemoteConfig{Name: \"origin\", URLs: []string{a.Repo}}) to register the remote. The wrap means go-git's CreateRemote failed, most commonly because a remote with the name 'origin' already exists in the freshly-initialized repository, or the RemoteConfig is invalid (e.g. empty URL).","triggerScenarios":"r.CreateRemote with name git.DefaultRemoteName ('origin') fails after PlainInit in the empty-repo fallback path of Load — i.e. a remote named 'origin' already exists (go-git ErrRemoteExists) or the config write to .git/config fails.","commonSituations":"Re-running an artifact load into a path where a previous run already created the origin remote; a leftover .git directory from a crashed previous attempt (PlainInit may have been skipped if the repo already existed earlier in a modified flow); disk/config write permission problems.","solutions":["Inspect the wrapped remoteErr: if it says 'remote already exists', delete the artifact path's .git directory so the fallback starts clean and retry.","Check that only one artifact writes to the same path; give each git artifact its own directory.","If the empty-repo case is expected (e.g. an initially-empty config repo), ensure the repo gets an initial commit so the normal PlainClone path is taken instead of the fallback.","Verify the pod can write .git/config (volume permissions, readOnlyRootFilesystem, securityContext)."],"exampleFix":"// before: failed because origin already existed\nif _, remoteErr := r.CreateRemote(&config.RemoteConfig{Name: git.DefaultRemoteName, URLs: []string{a.Repo}}); remoteErr != nil {\n// after: tolerate an existing identical remote\nif _, remoteErr := r.CreateRemote(&config.RemoteConfig{Name: git.DefaultRemoteName, URLs: []string{a.Repo}}); remoteErr != nil && !errors.Is(remoteErr, git.ErrRemoteExists) {\n    return fmt.Errorf(\"failed to create remote %q: %w\", a.Repo, remoteErr)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isRemoteExistsErr(err error) bool {\n\treturn errors.Is(err, git.ErrRemoteExists)\n}","tryCatchPattern":"err := artifactDriver.Load(ctx, artifact, path)\nif err != nil && strings.Contains(err.Error(), \"failed to create remote\") {\n\t// stale state from a previous attempt: start over with a clean path\n\tos.RemoveAll(path)\n\terr = artifactDriver.Load(ctx, artifact, path)\n}\nif err != nil {\n\treturn fmt.Errorf(\"git artifact load failed: %w\", err)\n}","preventionTips":["Use a fresh path per artifact and per retry; never share one path across steps.","Clean leftover .git directories from crashed runs before re-running the step.","Keep repos non-empty (initial commit) so the CreateRemote fallback is skipped.","Check volume write permissions so .git/config can be created."],"tags":["git","go-git","remote","artifact"],"backgroundTag":"git-remote-already-exists","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}