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

最终成功

相关推荐
人工干智能3 小时前
建自己的Python项目仓库,使用工具:GitHub(远程仓库)、GitHub Desktop(版本控制工具)、VSCode(代码编辑器)
python·编辑器·github
fouryears_234175 小时前
云服务器使用代理稳定与github通信方法
运维·服务器·github
angotech7 小时前
GitHub Copilot支持 GPT-5 和 GPT-5 mini!
github·copilot·ai编程·github copilot·gpt-5·copilot支持gpt-5
绝无仅有8 小时前
前端开发环境搭建:从安装 Node 到成功运行代码
后端·面试·github
xiaok8 小时前
分支管理提交代码
git·gitlab·github
绝无仅有8 小时前
某个互联网大厂的Elasticsearch基础面试题与答案
后端·面试·github
谢尔登10 小时前
【Git】merge 分类
git
NiKo_W10 小时前
Git 版本回退与撤销修改
开发语言·git·安全
Rhys..21 小时前
.gitignore文件的作用及用法
python·github
CoderJia程序员甲1 天前
GitHub 热榜项目 - 日榜(2025-09-12)
ai·github·开源项目·github热榜