{"record":{"id":"938d76bb9628cf20","repo":"zed-industries/zed","slug":"failed-to-add-remote-url-for-git-repository-git-dir","errorCode":null,"errorMessage":"failed to add remote {url} for git repository {git_dir:?}","messagePattern":"failed to add remote (.+?) for git repository (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/extension/src/extension_builder.rs","lineNumber":369,"sourceCode":"                .with_context(|| format!(\"creating grammar directory {directory:?}\"))?;\n            let init_output = util::command::new_command(\"git\")\n                .arg(\"init\")\n                .current_dir(directory)\n                .output()\n                .await?;\n            anyhow::ensure!(\n                init_output.status.success(),\n                \"failed to run `git init` in directory {directory:?}\"\n            );\n\n            let remote_add_output = util::command::new_command(\"git\")\n                .arg(\"--git-dir\")\n                .arg(&git_dir)\n                .args([\"remote\", \"add\", \"origin\", url])\n                .output()\n                .await\n                .context(\"executing `git remote add`\")?;\n            anyhow::ensure!(\n                remote_add_output.status.success(),\n                \"failed to add remote {url} for git repository {git_dir:?}\"\n            );\n        }\n\n        let fetch_output = util::command::new_command(\"git\")\n            .arg(\"--git-dir\")\n            .arg(&git_dir)\n            .args([\"fetch\", \"--depth\", \"1\", \"origin\", rev])\n            .output()\n            .await\n            .context(\"executing `git fetch`\")?;\n\n        let checkout_output = util::command::new_command(\"git\")\n            .arg(\"--git-dir\")\n            .arg(&git_dir)\n            .args([\"checkout\", rev])\n            .current_dir(directory)","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/extension/src/extension_builder.rs#L351-L387","documentation":"Raised in `checkout_repo` (crates/extension/src/extension_builder.rs:369) after a fresh `git init`, when `git --git-dir <dir>/.git remote add origin <url>` exits non-zero, so the builder cannot register the grammar repository's URL as the `origin` remote. Since the directory was just initialized, this failure is almost always an environment problem rather than a state conflict, and the subsequent shallow `git fetch` of the pinned revision cannot succeed without the remote.","triggerScenarios":"Calling `compile_grammar` -> `checkout_repo` for a grammar whose directory doesn't exist yet, where `git remote add origin <url>` fails: `git` not on PATH (process spawn failure is a distinct context error, but a non-zero status can occur if the directory is not actually a git repo, e.g. `git init` above silently skipped due to a wrapped/incompatible git binary), the .git dir is missing or corrupted between the two calls, an invalid remote name/URL rejected by git configuration (e.g. hooks/insteadOf rewriting the URL to empty), or file-system errors writing .git/config (read-only or full disk).","commonSituations":"Corporate git config with `url.<x>.insteadOf` or `insteadOf` rewrites corrupting the remote URL; antivirus or filesystem sync (Dropbox/OneDrive) locking .git/config on Windows; a full or read-only disk; custom GIT_DIR/GIT_CONFIG environment variables interfering with the spawned git process.","solutions":["Inspect .git/config in the grammar directory and remove any `url.*.insteadOf` global rewrites (`git config --global --unset url.ssh://... .insteadOf`) or unset GIT_CONFIG_GLOBAL conflicts, then retry the build.","Delete the grammar directory (`rm -rf <directory>`) so the builder re-runs `git init` and `remote add` from scratch.","Check that the parent filesystem is writable and not full (`df -h`, `mount | grep <path>`).","Unset interfering environment variables (GIT_DIR, GIT_WORK_TREE, GIT_CONFIG_GLOBAL) in the shell before building; the builder sets GIT_CONFIG_GLOBAL=/dev/null for some calls but not all."],"exampleFix":"// before (shell): global insteadOf rewrite breaks remote add\n$ git config --global url.\"ssh://git@corp/\".insteadOf \"https://github.com/\"\n$ zed: error: failed to add remote https://github.com/tree-sitter/tree-sitter-yaml ...\n\n// after (shell): scope the rewrite only to work repos, or unset it\n$ git config --global --unset-all url.\"ssh://git@corp/\".insteadOf\n$ rm -rf ~/.local/share/zed/extensions/work/tree-sitter-yaml","handlingStrategy":"validation","validationCode":"// Remove git config rewrites and env interference before building\nconst { execSync } = require('child_process');\nfunction precheck(url) {\n  delete process.env.GIT_DIR;\n  delete process.env.GIT_WORK_TREE;\n  try {\n    execSync(`git config --global --get-regexp 'url\\..*\\.insteadof'`, { stdio: 'pipe' });\n    console.warn('global url.insteadOf rewrites present; they may corrupt remote add');\n  } catch { /* none found */ }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await buildExtension(path);\n} catch (err) {\n  if (String(err).includes(\"failed to add remote\")) {\n    console.error(\"Check .git/config, url.insteadOf rewrites, and disk writability:\", err.message);\n  }\n  throw err;\n}","preventionTips":["Avoid global `url.*.insteadOf` rewrites, or scope them to specific hosts only.","Keep grammar cache directories off cloud-synced folders (Dropbox/OneDrive) that can lock .git files.","Unset GIT_DIR/GIT_WORK_TREE/GIT_CONFIG_GLOBAL in build environments.","Ensure sufficient disk space before building extensions."],"tags":["git","build","environment","command-failed"],"backgroundTag":"git-command-failed","analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-09-12T19:35:53.743Z","contentChangedAt":"2026-09-12T19:35:53.743Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}