gastownhall/beads · error

remove existing remote %s: %w

Error message

remove existing remote %s: %w

What it means

When ensureDoltRemote finds an existing remote with the same name but a different URL, it removes the old remote before adding the new one. If RemoveRemote fails and the remote was visible in the live listing (not disk-only), the removal error is wrapped as 'remove existing remote <name>'. Disk-only remotes are tolerated because the subsequent confirmed add re-establishes the URL.

Source

Thrown at cmd/bd/dolt.go:1582

		if err := st.AddRemote(ctx, name, url); err != nil {
			return doltRemoteAddResult{}, fmt.Errorf("add remote %s: %w", name, err)
		}
		return doltRemoteAddResult{}, nil
	}

	if doltutil.RemoteURLsMatch(existingURL, url) {
		return doltRemoteAddResult{}, nil
	}

	if !confirm("SQL server", name, existingURL, url) {
		return doltRemoteAddResult{Canceled: true}, nil
	}
	if err := st.RemoveRemote(ctx, name); err != nil {
		// A remote known only from disk may not be removable through a
		// cold-started server that doesn't see it yet; the confirmed add
		// below is what establishes the new URL either way.
		if !existingFromDiskOnly {
			return doltRemoteAddResult{}, fmt.Errorf("remove existing remote %s: %w", name, err)
		}
	}
	if err := st.AddRemote(ctx, name, url); err != nil {
		return doltRemoteAddResult{}, fmt.Errorf("add remote %s: %w", name, err)
	}
	return doltRemoteAddResult{}, nil
}

var doltRemoteCmd = &cobra.Command{
	Use:   "remote",
	Short: "Manage Dolt remotes",
	Long: `Manage Dolt remotes for push/pull replication.

Subcommands:
  add <name> <url>     Add a new remote
  list                 List all configured remotes
  remove <name>        Remove a remote
  reset-data <name>    Replace a remote's data plane after a history squash`,

View on GitHub (pinned to 71377f2769)

Solutions

  1. Read the wrapped cause; restart the Dolt server session (re-run the command) to clear stale state
  2. Verify current remotes with `bd dolt remote -v`, remove the conflicting one explicitly, then add the new URL
  3. Check for concurrent bd processes and serialize remote operations
  4. If the server persistently cannot remove it, restore .beads dolt state from refs/dolt/data in git

Example fix

// before
bd dolt remote add origin https://new-url  # fails if old origin unremovable
// after
bd dolt remote remove origin
bd dolt remote add origin https://new-url
Defensive patterns

Strategy: try-catch

Validate before calling

remotes, err := st.ListRemotes(ctx)
if err == nil {
  for _, r := range remotes {
    if r.Name == name && r.URL != newURL {
      fmt.Printf("remote %s will be replaced: %s -> %s\n", name, r.URL, newURL)
    }
  }
}

Try / catch

res, err := ensureDoltRemote(ctx, st, name, url, confirm)
if err != nil {
  if strings.Contains(err.Error(), "remove existing remote "+name) {
    // stale server state: recreate the session or remove the remote explicitly, then retry
    return res, err
  }
}

Prevention

When it happens

Trigger: Changing a remote's URL via `bd dolt remote add <name> <new-url>` where RemoveRemote fails: server write error, remote locked, or driver-level failure — only when the remote was already visible to the running server.

Common situations: Pointing an existing 'origin' at a new repo URL; stale server state after a database restore; another process mutating remotes concurrently.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/7cb6b0167e746d62. Report an issue: GitHub.