gitbutlerapp/gitbutler · error

Remote with url '{url}' already exists at '{remote_name}'

Error message

Remote with url '{url}' already exists at '{remote_name}'

What it means

Thrown by the add_remote command when a different remote already fetches from the exact same URL. After the name check passes, the command scans every configured remote's fetch URL and refuses a duplicate, naming the existing remote in the message. This dedupes remotes so GitButler never ends up with two names for the same server-side repository.

Source

Thrown at crates/gitbutler-repo/src/commands.rs:259

        if let Some(remote_name) = repo
            .remote_names()
            .iter()
            .filter_map(|name| repo.find_remote(name).ok())
            .find_map(|remote| {
                remote
                    .url(gix::remote::Direction::Fetch)
                    .and_then(|remote_url| {
                        if remote_url.to_bstring() == url {
                            remote
                                .name()
                                .and_then(|n| n.as_symbol().map(ToOwned::to_owned))
                        } else {
                            None
                        }
                    })
            })
        {
            bail!("Remote with url '{url}' already exists at '{remote_name}'");
        }

        edit_repo_config(&repo, gix::config::Source::Local, |config| {
            let mut section = config.section_mut_or_create_new("remote", Some(name.into()))?;
            section.push("url", Some(url.as_bytes().as_bstr()))?;
            ensure_config_value(
                config,
                &format!("remote.{name}.fetch"),
                &format!("+refs/heads/*:refs/remotes/{name}/*"),
            )?;
            Ok(())
        })?;
        Ok(())
    }

    fn read_file_from_commit(
        &self,
        commit_id: gix::ObjectId,

View on GitHub (pinned to caf1f223d3)

Solutions

  1. Reuse the existing remote named in the error message instead of adding a new one
  2. If the new remote must differ, use a genuinely different URL form (e.g. ssh vs https, or the fork's URL)
  3. Remove the existing remote first if it is obsolete: git remote remove <existing_name>

Example fix

# before: add_remote('upstream', 'https://github.com/org/repo.git')
#        -> "Remote with url '...' already exists at 'origin'"
# after: origin already points there - just use it
git remote -v
Defensive patterns

Strategy: validation

Validate before calling

let repo = gix::open(&workdir)?;
let url_taken = repo.remote_names().iter()
    .filter_map(|n| repo.find_remote(n).ok())
    .filter_map(|r| r.url(gix::remote::Direction::Fetch))
    .any(|u| u.to_bstring() == url);
if url_taken {
    // a remote already fetches this URL; skip add_remote and reuse it
}

Prevention

When it happens

Trigger: Calling add_remote with a fresh name (e.g. 'upstream') whose URL string-equals the fetch URL of an existing remote (e.g. 'origin') - the filter_map over remote_names()/find_remote finds the match and the bail fires.

Common situations: Adding a second remote for the same GitHub repo (mirror/fork workflows) with the identical URL; copy-pasting the origin URL into the add-remote dialog; provisioning automation that runs on clones where the remote already exists under another name.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20). Data as JSON: /api/errors/fa43b6cef1bea881. Report an issue: GitHub.