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

最终成功

相关推荐
bzmK1DTbd8 小时前
Git版本控制:Java项目中的分支管理与合并策略
java·开发语言·git
OYangxf12 小时前
Git基础概念
git
YuePeng13 小时前
我用 30 行 Java 注解,做出了别人花三周写的管理后台,还顺手接入了 DeepSeek
后端·github
weixin_4022784515 小时前
VS code 本地推送github添加SSH设置
运维·git·ssh
无心水16 小时前
【Hermes:MCP 与工具实战】28、GitHub MCP 深度实战:PR 审查、Issue、自动汇报全搞定
人工智能·github·issue·openclaw·养龙虾·hermes·honcho
逛逛GitHub16 小时前
GitHub 上狂揽 1.8 万 Star!开源平替的 Claude Design。
github
笑望灬星辰17 小时前
VS Code 编辑器 Git 工具 - 分支操作【保姆级教程】
git·vscode·编辑器
shisanjin12317 小时前
关于 IDEA2025 版本中对 git 的操作与使用
git·github·idea
熬夜敲代码的小N17 小时前
鸿蒙PC开发者必备!GitNext深度测评:一站式Git管理工具
git·华为·harmonyos
坚果派·白晓明17 小时前
【开发者必备工具】Windows 11 安装 Git 完整指南
windows·git·项目开发必备工具·参与开源项目必备工具