jesseduffield/lazygit · error

Remote {{.remoteName}} already exists and has different URL

Error message

Remote {{.remoteName}} already exists and has different URL

What it means

Returned by RemotesController.ensureForkRemoteAndCheckout when a remote with the fork's name already exists but none of its URLs match the fork URL (slices.Contains(remote.Urls, remoteUrl) is false). Rather than silently re-pointing an existing remote, lazygit refuses because the name collision may refer to a different repository.

Source

Thrown at pkg/gui/controllers/remotes_controller.go:189

				}
			}

			// Fetch the remote
			return self.fetchAndCheckout(self.c.Contexts().Remotes.GetSelected(), branchToCheckout)
		},
	})
	return nil
}

// Ensures the fork remote exists (matching the given URL).
// If it exists and matches, it’s selected and fetched; otherwise, it’s created and then fetched and checked out.
// If it does exist but with a different URL, an error is returned.
func (self *RemotesController) ensureForkRemoteAndCheckout(remoteName string, remoteUrl string, branchToCheckout string) error {
	for idx, remote := range self.c.Model().Remotes {
		if remote.Name == remoteName {
			hasTheSameUrl := slices.Contains(remote.Urls, remoteUrl)
			if !hasTheSameUrl {
				return errors.New(utils.ResolvePlaceholderString(
					self.c.Tr.IncompatibleForkAlreadyExistsError,
					map[string]string{
						"remoteName": remoteName,
					},
				))
			}
			self.c.Contexts().Remotes.SetSelection(idx)
			return self.fetchAndCheckout(remote, branchToCheckout)
		}
	}
	return self.addAndCheckoutRemote(remoteName, remoteUrl, branchToCheckout)
}

func (self *RemotesController) add() error {
	self.c.Prompt(types.PromptOpts{
		Title: self.c.Tr.NewRemoteName,
		HandleConfirm: func(remoteName string) error {
			self.c.Prompt(types.PromptOpts{

View on GitHub (pinned to c477a2959b)

Solutions

  1. Run 'git remote set-url <remoteName> <forkUrl>' so the existing remote matches the fork, then retry.
  2. Remove the conflicting remote (remotes panel) and let the fork flow re-create it.
  3. If both remotes are legitimately needed, rename one before retrying the fork flow.

Example fix

# before
$ git remote -v
fork  git@github.com:someone/other-repo.git (fetch)

# after
$ git remote set-url fork https://github.com/you/your-fork.git
Defensive patterns

Strategy: validation

Validate before calling

func remoteMatchesUrl(remote *models.Remote, url string) bool {
    return slices.Contains(remote.Urls, url)
}
// before fork flow: ensure remoteMatchesUrl or remote absent

Prevention

When it happens

Trigger: Using the 'fork' flow (create/open fork) where remoteName already exists in Model().Remotes with different URLs — e.g. 'origin' or the fork name already pointing at another clone URL (https vs ssh, or someone else's fork).

Common situations: Remote was renamed or hand-added with an SSH URL while the fork flow uses HTTPS (or vice versa); a same-named remote from a previous fork attempt; corporate mirrors where URLs get rewritten.

Related errors


AI-assisted analysis of jesseduffield/lazygit@c477a2959b (2026-08-15). Data as JSON: /api/errors/dfc663923b77dbf4. Report an issue: GitHub.