You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决create-react-app的Git仓库未初始化错误(git --version执行失败)

使用npx create-react-app创建React项目时的Git初始化错误解析与解决

错误含义

这个错误说明:create-react-app自动初始化Git仓库的操作失败,核心原因是系统无法执行git --version命令——要么你的电脑未安装Git,要么Git未被添加到系统环境变量中,导致终端无法识别Git相关指令。

注意:项目本身已经创建成功,只是自动初始化Git仓库的步骤未完成。

解决步骤

  • 检查Git安装状态:打开命令提示符/终端,输入git --version,若提示“找不到git命令”,说明未安装Git。
  • 安装Git:下载对应系统的Git安装包,安装时务必勾选「Add Git to PATH」选项,确保Git能被终端全局调用。
  • 验证安装效果:重启终端后,再次执行git --version,能正常显示Git版本号即表示安装成功。
  • 手动初始化Git(可选):若不想重新创建项目,进入已生成的项目目录执行以下命令,手动完成Git仓库初始化:
    cd mynews-app
    git init
    

报错详情

npx create-react-app mynews-app

231 packages are looking for funding
  run `npm fund` for details
Git repo not initialized Error: Command failed: git --version
    at checkExecSyncError (node:child_process:885:11)
    at execSync (node:child_process:957:15)
    at tryGitInit (C:\Users\sapar\OneDrive\Desktop\Project\ReactJs\mynews-app\node_modules\react-scripts\scripts\init.js:46:5)
    at module.exports (C:\Users\sapar\OneDrive\Desktop\Project\ReactJs\mynews-app\node_modules\react-scripts\scripts\init.js:276:7)
    at [eval]:3:14
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:307:38)
    at node:internal/process/execution:79:19
    at [eval]-wrapper:6:22 {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 13968,
  stdout: null,
  stderr: null
}

Installing template dependencies using npm...

added 55 packages in 9s

231 packages are looking for funding
    Bundles the app into static files for production.

  npm test
    Starts the test runner.

  npm run eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd mynews-app
  npm start

Happy hacking!

内容的提问来源于stack exchange,提问作者Dhara Patel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 08:45:46