{"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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-repo/src/commands.rs","lineNumber":237,"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":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/gitbutler-repo/src/commands.rs#L219-L255","documentation":"Thrown by the add_remote command (gitbutler-repo) when a git remote with the requested name is already configured in the repository. The command deliberately refuses to overwrite: it calls repo.find_remote(name) first and bails before touching the config. Raw git would let you shadow or re-add in some flows, so users migrating scripts from plain git are often surprised.","triggerScenarios":"Calling the GitButler add_remote command (desktop add-remote dialog, SDK, or CLI) with a name like 'origin' in a repository whose .git/config already contains a remote with that exact name, so the initial find_remote(name).is_ok() check trips.","commonSituations":"Re-adding origin after changing its URL (should be an edit, not an add); onboarding/setup scripts run twice; automation assuming a clean clone; users intending to update the URL of an existing remote rather than create one.","solutions":["Check existing remotes first (git remote -v, or the list_remotes command) and skip the add if the name exists","If you meant to change the URL of the existing remote, edit it instead: git remote set-url <name> <url>","Pick a different remote name if you genuinely need a second remote for a different URL","Remove the old remote first (git remote remove <name>) if it should really be replaced"],"exampleFix":"# before: add_remote('origin', url) -> \"Remote name 'origin' already exists\"\n# after: update the existing remote instead of adding a duplicate\ngit remote set-url origin https://github.com/org/repo.git","handlingStrategy":"validation","validationCode":"let repo = gix::open(&workdir)?;\nif repo.remote_names().iter().any(|n| n == name) {\n    // name taken: update the existing remote's url instead of calling add_remote\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["List remotes before adding","Treat 'add existing name' as an update-url operation in automation","Make onboarding scripts idempotent by checking remote names first"],"tags":["git","remote","duplicate","git-config"],"backgroundTag":"git-remote-already-exists","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}