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

最终成功

相关推荐
黑客思维者7 小时前
Python大规模数据处理OOM突围:从迭代器原理到TB级文件实战优化
开发语言·python·github·迭代器·oom
草梅友仁9 小时前
草梅 Auth 1.11.1 版本发布与 AI 辅助代码重构实践 | 2025 年第 49 周草梅周报
开源·github·ai编程
ChinaRainbowSea10 小时前
github 仓库主页美化定制
java·后端·github
粥里有勺糖11 小时前
视野修炼-技术周刊第128期 | Bun 被收购
前端·javascript·github
熊猫钓鱼>_>12 小时前
GitHub Actions CI/CD流水线实战指南
ci/cd·github
旅之灵夫13 小时前
【GitHub项目推荐--Agent Rules:AI编码助手的规则引擎与知识库系统】
github
@YDWLCloud15 小时前
用腾讯云国际版搭建全球加速架构:5 分钟实现多地访问提速
服务器·架构·云计算·github·腾讯云
skywalk816316 小时前
为一个库设置多个远程更新站用于git push,比如gitcode github等
git·github·gitcode
雪碧聊技术16 小时前
银河麒麟安装git
git
_OP_CHEN16 小时前
【Git原理与使用】(一)告别文件混乱!Git 初识:从版本灾难到高效管理的终极方案
linux·运维·git·github·运维开发·版本控制·企业级组件