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

最终成功

相关推荐
DianSan_ERP14 小时前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
慢慢开始吧15 小时前
Redmi Note 7 Pro (Violet) 爆改满血 Linux 掌上服务器指南
github
模型时代17 小时前
GitHub Codespaces存在RoguePilot漏洞,可致GitHub令牌泄露
github
webkubor17 小时前
AI 时代的 robots.txt:深度解析 llms.txt 规范与项目“AI 原生化”改造实战
github
i学长的猫19 小时前
obsidian md github站点
github
jack@london20 小时前
使用Railway
github
CoderJia程序员甲20 小时前
GitHub 热榜项目 - 日榜(2026-02-25)
人工智能·ai·大模型·github·ai教程
红豆子不相思21 小时前
Tomcat 环境搭建与集群实战
服务器·git·tomcat
杰哥技术分享1 天前
Git 仓库迁移技术文档:从 CODING.net 迁移至腾讯云 CNB
git
给老吕螺丝1 天前
提升国内访问GitHub稳定性的解决方案:Steamcommunity 302工具详解 (Ver.13.0.05+)
经验分享·github