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

最终成功

相关推荐
ControlRookie3 小时前
SyncBridge:一个 CODESYS 工程与 AI 之间工程师级的同步工具
git·ai编程·codesys·工业软件·controlrookie
最强小杰9 小时前
Claude Opus 4.8 调用一直报 529 怎么办?同样请求换旧模型却正常——附 429/529 双桶退避代码
ai·github
鬼手点金11 小时前
opencode-性能优化建议
java·人工智能·git·自动化·nanogpt
来自于狂人12 小时前
GitHub 开源趋势日报 | 2026年10月7日用 AI Agent 逆向工程一切
人工智能·开源·github
逛逛GitHub13 小时前
盘点 20 个 9 月份 GitHub 上顶顶顶的开源项目。
github
网络毒刘13 小时前
开源 Aider 工作流实战:Git 提交驱动的 AI 结对,与 Cursor 何时互补
git·ai编程·cursor·aider
miofly13 小时前
Google 发布 EmbeddingGemma 2:7.4 亿参数的多模态嵌入模型
开源·github
wflynn14 小时前
GitHub 今日推荐|lightcraft:纯 Rust 重写的 RAW 照片开发工具
rust·开源·github·lightroom·art·photography
wflynn15 小时前
GitHub 日榜趋势速报 | 2026-10-07
开源·github
孟陬15 小时前
#教程 dw, dm, dy, d18m 是何意?万物可 Badge | 定制漂亮精致小徽章,打造眼前一亮 README
npm·github