{"record":{"id":"0821ef923c4092a1","repo":"gitbutlerapp/gitbutler","slug":"remote-name-name-already-exists","errorCode":null,"errorMessage":"Remote name '{name}' already exists","messagePattern":"Remote name '(.+?)' already exists","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-repo/src/commands.rs","lineNumber":252,"sourceCode":"    }\n\n    fn remotes(&self) -> anyhow::Result<Vec<GitRemote>> {\n        let repo = self.repo.get()?;\n        repo.remote_names()\n            .iter()\n            .map(|name| -> Result<_> {\n                let remote = repo.find_remote(name)?;\n                Ok(GitRemote::from_gix(name.to_string(), &remote))\n            })\n            .collect()\n    }\n\n    fn add_remote(&self, name: &str, url: &str) -> Result<()> {\n        let repo = self.open_isolated_repo()?;\n\n        // Bail if remote with given name already exists.\n        if repo.find_remote(name).is_ok() {\n            bail!(\"Remote name '{name}' already exists\");\n        }\n\n        // Bail if remote with given url already exists.\n        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                        }","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-repo/src/commands.rs#L234-L270","documentation":"add_remote in crates/gitbutler-repo refuses to create a git remote when a remote with the same name already exists in the repository. Git itself would overwrite or conflict, so the API bails explicitly before mutating repo config.","triggerScenarios":"Calling add_remote(name, url) when repo.find_remote(name) resolves — i.e., a remote named `name` (e.g. \"origin\") is already configured.","commonSituations":"Re-running an init/sync routine that adds \"origin\" a second time; user already cloned the repo so origin exists; two integrations trying to register the same remote name.","solutions":["Check for the existing remote first and reuse/skip it instead of adding.","Use a different remote name.","If the existing remote's URL is wrong, update it (edit repo config remote.<name>.url) rather than re-adding."],"exampleFix":"// before\nrepo.add_remote(\"origin\", &url)?;\n// after\nif repo.find_remote(\"origin\").is_err() {\n    repo.add_remote(\"origin\", &url)?;\n}","handlingStrategy":"validation","validationCode":"let exists = repo.find_remote(name).is_ok();\nif exists { /* skip add or update URL instead */ }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"already exists\") => {\n        // reuse existing remote\n    }\n    Err(e) => return Err(e),\n    Ok(r) => r,\n}","preventionTips":["Always check find_remote before adding.","Make remote-adding routines idempotent.","Use stable, unique remote names per integration."],"tags":["git","remote","duplicate","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"}