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

如何从Linux终端将正确的React项目上传至GitHub

解决React项目上传GitHub错误的步骤

1. 确认当前终端处于目标项目根目录

先执行命令查看当前路径:

pwd

对比你的React项目实际存储路径,确保完全一致。如果路径不对,用cd命令切换到正确目录,比如:

cd /home/your-username/your-react-app-folder

2. 检查并修正远程仓库关联

执行命令查看当前关联的远程仓库:

git remote -v

如果显示的不是你新创建的GitHub仓库地址,重新设置:

git remote remove origin
git remote add origin https://github.com/*****/******.git

3. 确保本地Git仓库与当前项目匹配

如果你的本地项目Git历史是之前项目的残留,彻底重置:

# 删除原有Git仓库文件
rm -rf .git
# 重新初始化Git
git init
# 添加当前项目所有文件
git add .
# 提交初始版本
git commit -m "Initial commit for React app"

4. 推送至GitHub

git branch -M main
git push -u origin main

如果远程仓库已有错误内容需要覆盖,添加--force参数:

git push -u origin main --force

内容的提问来源于stack exchange,提问作者Giovanni El Zelah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 00:45:14