{"record":{"id":"fa43b6cef1bea881","repo":"gitbutlerapp/gitbutler","slug":"remote-with-url-url-already-exists-at-remote","errorCode":null,"errorMessage":"Remote with url '{url}' already exists at '{remote_name}'","messagePattern":"Remote with url '(.+?)' already exists at '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-repo/src/commands.rs","lineNumber":274,"sourceCode":"        if let Some(remote_name) = repo\n            .remote_names()\n            .iter()\n            .filter_map(|name| repo.find_remote(name).ok())\n            .find_map(|remote| {\n                remote\n                    .url(gix::remote::Direction::Fetch)\n                    .and_then(|remote_url| {\n                        if remote_url.to_bstring() == url {\n                            remote\n                                .name()\n                                .and_then(|n| n.as_symbol().map(ToOwned::to_owned))\n                        } else {\n                            None\n                        }\n                    })\n            })\n        {\n            bail!(\"Remote with url '{url}' already exists at '{remote_name}'\");\n        }\n\n        edit_repo_config(&repo, gix::config::Source::Local, |config| {\n            let mut section = config.section_mut_or_create_new(\"remote\", Some(name.into()))?;\n            section.push(\"url\", Some(url.as_bytes().as_bstr()))?;\n            ensure_config_value(\n                config,\n                &format!(\"remote.{name}.fetch\"),\n                &format!(\"+refs/heads/*:refs/remotes/{name}/*\"),\n            )?;\n            Ok(())\n        })?;\n        Ok(())\n    }\n\n    fn read_file_from_commit(\n        &self,\n        commit_id: gix::ObjectId,","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-repo/src/commands.rs#L256-L292","documentation":"add_remote also refuses to add a remote whose URL is already used by another remote in the repository, reporting which remote name already points at that URL. This prevents two remotes with identical URLs.","triggerScenarios":"Calling add_remote(name, url) when some existing remote's URL equals `url` (case-insensitive scan of repo.remote_names()), e.g. adding \"upstream\" with the same URL as \"origin\".","commonSituations":"Adding the same repository under a new name; re-running onboarding against an already-configured repo; typo where the new remote's URL duplicates an existing one.","solutions":["Reuse the existing remote name reported in the message instead of adding a new one.","Choose a different repository/URL if you truly need a second remote.","Remove the existing remote (git remote remove <name>) if it should be replaced, then add the new one."],"exampleFix":"// before\nrepo.add_remote(\"upstream\", \"https://github.com/org/repo.git\")?; // same URL as origin\n// after\nrepo.add_remote(\"upstream\", \"https://github.com/org/fork.git\")?;","handlingStrategy":"validation","validationCode":"let url_taken = repo.remote_names().iter().any(|n| {\n    repo.find_remote(n).ok()\n        .and_then(|r| r.url().map(|u| u == url))\n        .unwrap_or(false)\n});\nif url_taken { /* reuse the existing remote */ }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"already exists\") => {\n        // resolve the reported remote_name and reuse it\n    }\n    Err(e) => return Err(e),\n    Ok(r) => r,\n}","preventionTips":["Scan existing remote URLs before registering a new remote.","Keep one canonical remote per URL.","Make onboarding flows idempotent (lookup-then-create)."],"tags":["git","remote","duplicate","url","rust"],"backgroundTag":"file-already-exists","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}