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

最终成功

相关推荐
国家二级编程爱好者31 分钟前
删除typora文档没有引用的资源文件
git·python
阿里嘎多学长44 分钟前
2026-03-11 GitHub 热点项目精选
开发语言·程序员·github·代码托管
Yupureki1 小时前
《C++实战项目-高并发内存池》5.PageCache构造
c语言·开发语言·c++·单例模式·github
Rsun045514 小时前
Git相关面试题
git
zhping10115 小时前
Linux 系统上使用 GitHub 加速工具
linux·运维·github
rogerogers6 小时前
在 VS Code Remote SSH 中完美配置 GPG 自动签名 (macOS 到 Ubuntu 24.04)
git·visual studio code
qiuyuyiyang7 小时前
Nginx 反向代理之upstream模块以及完整配置反向代理示例
git·nginx·github
CoderJia程序员甲7 小时前
GitHub 热榜项目 - 日榜(2026-03-14)
人工智能·ai·大模型·github·ai教程
猫头虎7 小时前
如何解决openclaw安装skills报错command not foud:clawhub问题怎么解决?
langchain·开源·prompt·github·aigc·ai编程·内容运营
汪海游龙8 小时前
03.15 AI 精选:Claude Opus/Sonnet 4.6 开放 100 万上下文
github·hacker news