【问题解决】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

最终成功

相关推荐
WebGirl7 分钟前
代码Revert后再次Merge会丢失的问题
git
T__TIII1 小时前
Dify 自定义插件
人工智能·github
小皮侠5 小时前
nginx的使用
java·运维·服务器·前端·git·nginx·github
汪汪队睡大觉755 小时前
OpenAI-Kotlin文档详解
github
蛋黄蛋黄5 小时前
微信表情怎么在自己的项目使用微信表情?-> [开源仓库]wechat-emoji
前端·github
HalukiSan6 小时前
如何提交PR
git·gitlab·github
掘金安东尼6 小时前
前端周刊第421期(2025年7月1日–7月6日)
前端·面试·github
小林up8 小时前
github push:ssh: connect to host github.com port 22
运维·ssh·github
Leinwin15 小时前
微软开源GitHub Copilot Chat,AI编程领域迎新突破
microsoft·github·copilot
爱莉希雅&&&17 小时前
shell编程之awk命令详解
linux·服务器·git