【问题解决】Github上手动Delete file之后, git remote add+git push出错

之前某一个仓库,因为git操作不熟练,文件是手动在GitHub页面上上传上去的,但现在因为学习了进阶的技术,所以希望合并,并把本地文件夹和远程仓库建立连接。【其中出现了一些问题,不过借助gpt都得到了解决】

首先是在GitHub页面上手动 delete file

然后在一个新文件夹中 git init, git add, git commit后,git remote add出问题。一直卡在这一步:

gpt建议

但我这里是没有这个origin的

所以我把git remote 和 git push的报错都截图给她

git push --set-upstream origin main依旧报错


然后就可以了

不过后面又有报错

javascript 复制代码
$ git push -u origin main
To https://github.com/aPurpleBerry/javascript.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/aPurpleBerry/javascript.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

这个错误提示是因为远程仓库上存在一些提交记录,而你的本地仓库没有这些记录。Git 为了避免覆盖远程的更改,拒绝了推送请求。

git pull origin main --rebase

git push origin main

最终成功

相关推荐
GoGeekBaird2 小时前
分享几个使用Nano Banana Pro 画信息图的提示词
后端·github
Mr_Dwj4 小时前
【工具】Git 子仓库管理
git
UVM_ERROR5 小时前
RDMA Scheduler + TX + Completion RTL 开发经验分享
笔记·vscode·ssh·github·芯片
Salt_07285 小时前
DAY 36 官方文档的阅读
python·算法·机器学习·github
粟悟饭&龟波功6 小时前
【GitHub热门项目精选】(2025-12-19)
前端·人工智能·后端·github
天勤量化大唯粉8 小时前
枢轴点反转策略在铜期货中的量化应用指南(附天勤量化代码)
ide·python·算法·机器学习·github·开源软件·程序员创富
CoderJia程序员甲8 小时前
GitHub 热榜项目 - 日榜(2025-12-19)
ai·开源·llm·github
小明_GLC9 小时前
关于Pycharm中导入github项目,出现依赖包报错
github
张小九9911 小时前
fpocket安装和使用教程
linux·机器学习·github
Rysxt_12 小时前
Git Rebase 变基教程:作用、使用场景与合并的区别
git·变基