argoproj/argo-workflows · error

failed to create remote %q: %w

Error message

failed to create remote %q: %w

What it means

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).

Source

Thrown at workflow/artifacts/git/git.go:141

		InsecureSkipTLS: g.InsecureSkipTLS,
	}
	if a.SingleBranch && a.Branch == "" {
		return errors.New("single branch mode without a branch specified")
	}
	if a.SingleBranch {
		cloneOptions.ReferenceName = plumbing.NewBranchReferenceName(a.Branch)
	}

	r, err := git.PlainClone(path, false, cloneOptions)
	if errors.Is(err, transport.ErrEmptyRemoteRepository) {
		logging.RequireLoggerFromContext(ctx).Info(ctx, "Cloned an empty repository")
		var initErr error
		r, initErr = git.PlainInit(path, false)
		if initErr != nil {
			return fmt.Errorf("failed to plain init: %w", initErr)
		}
		if _, remoteErr := r.CreateRemote(&config.RemoteConfig{Name: git.DefaultRemoteName, URLs: []string{a.Repo}}); remoteErr != nil {
			return fmt.Errorf("failed to create remote %q: %w", a.Repo, remoteErr)
		}
		branchName := a.Revision
		if branchName == "" {
			branchName = "master"
		}
		if err = r.CreateBranch(&config.Branch{Name: branchName, Remote: git.DefaultRemoteName, Merge: plumbing.Master}); err != nil {
			return fmt.Errorf("failed to create branch %q: %w", branchName, err)
		}
		return nil
	} else if err != nil {
		return fmt.Errorf("failed to clone %q: %w", a.Repo, err)
	}
	if len(a.Fetch) > 0 {
		refSpecs := make([]config.RefSpec, len(a.Fetch))
		for i, spec := range a.Fetch {
			refSpecs[i] = config.RefSpec(spec)
		}
		opts := &git.FetchOptions{Auth: auth, RefSpecs: refSpecs, Depth: depth, InsecureSkipTLS: g.InsecureSkipTLS}

View on GitHub (pinned to 35bff19146)

Solutions

  1. Inspect the wrapped remoteErr: if it says 'remote already exists', delete the artifact path's .git directory so the fallback starts clean and retry.
  2. Check that only one artifact writes to the same path; give each git artifact its own directory.
  3. 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.
  4. Verify the pod can write .git/config (volume permissions, readOnlyRootFilesystem, securityContext).

Example fix

// before: failed because origin already existed
if _, remoteErr := r.CreateRemote(&config.RemoteConfig{Name: git.DefaultRemoteName, URLs: []string{a.Repo}}); remoteErr != nil {
// after: tolerate an existing identical remote
if _, remoteErr := r.CreateRemote(&config.RemoteConfig{Name: git.DefaultRemoteName, URLs: []string{a.Repo}}); remoteErr != nil && !errors.Is(remoteErr, git.ErrRemoteExists) {
    return fmt.Errorf("failed to create remote %q: %w", a.Repo, remoteErr)
}
Defensive patterns

Strategy: try-catch

Type guard

func isRemoteExistsErr(err error) bool {
	return errors.Is(err, git.ErrRemoteExists)
}

Try / catch

err := artifactDriver.Load(ctx, artifact, path)
if err != nil && strings.Contains(err.Error(), "failed to create remote") {
	// stale state from a previous attempt: start over with a clean path
	os.RemoveAll(path)
	err = artifactDriver.Load(ctx, artifact, path)
}
if err != nil {
	return fmt.Errorf("git artifact load failed: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/bb658139803e4065. Report an issue: GitHub.