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

最终成功

相关推荐
粥里有勺糖11 小时前
视野修炼-技术周刊第139期 | AI 不会让时间变多
前端·github·ai编程
一点一木13 小时前
🚀 2026 年 11 月 GitHub 十大热门项目排行榜 🔥
人工智能·github
OpenTiny社区15 小时前
当 AI 开始写 UI,我们缺的不是模型,是"设计词汇"
前端·github·ai编程
逛逛GitHub15 小时前
Codex 自带的远程功能用着不爽,直接换成这个远程控制神器了。
github
CoderJia程序员甲15 小时前
GitHub 热榜项目 - 周榜(2026-11-28)
github
Zucker n15 小时前
Git 常用命令速查(自用笔记)
git
LiuPig刘皮哥15 小时前
github桌宠desktop-pet star前22在干嘛?
github·桌宠·xiaokeai
七牛云行业应用16 小时前
Antigravity 迁移清单:Claude Code、Codex、Cursor 哪些能带过来
人工智能·ai·github
欧雷殿17 小时前
没有数据勿谈智能:揭秘我的数据底座
数据挖掘·github·ai编程
心如鉄补18 小时前
GitHub Actions 自动化:5 个真实运维提效案例
运维·自动化·github