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

最终成功

相关推荐
aramae4 小时前
C++11:现代C++的里程碑
c语言·开发语言·c++·windows·git·后端
BerryS3N6 小时前
GitHub Actions自动化运维实战:从CI/CD到云端部署的完整指南
运维·自动化·github
胡萝卜术6 小时前
V040:RAG 检索增强生成的工程链路解构与生产级系统设计
面试·架构·github
工具派8 小时前
从 git commit 到交付 PDF:我的一条在线工具流实录
git·elasticsearch·pdf
鱼樱前端16 小时前
别再自己拼凑了!这款 Vue 3.5+ 严肃产品级组件库,把 AI 对话、工作流和复杂数据全包了!
javascript·vue.js·github
阿里嘎多学长18 小时前
2026-07-14 GitHub 热点项目精选
开发语言·程序员·github·代码托管
IpdataCloud19 小时前
跨区服玩家延迟高怎么办?用IP离线库自动分配到最近服务器
数据库·tcp/ip·github·php·ip
OpenTiny社区21 小时前
TinyEngine 2.11版本发布:AI 进一步融入画布,Vue 工程可一键转DSL
前端·vue.js·github
七牛开发者1 天前
RAG 工程里的上下文剪枝:如何减少 68% 的上下文
前端·css·github
咋吃都不胖lyh1 天前
提交(Commit)到本地的 Git 仓库,然后才能推送(Push)到远程的 Git 仓库
git