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

最终成功

相关推荐
T - mars24 分钟前
Git在Pycharm中的使用
git
sunarmy1 小时前
curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104
git
liangdabiao2 小时前
3分钟打造一个无敌的落地页Landing Page - 任何内容都完全自动化
程序员·github
典学长编程2 小时前
高效学习之一篇搞定分布式管理系统Git !
大数据·git·搜索引擎
是2的10次方啊3 小时前
.gitignore失效自救指南:原理揭秘与工程师实战排查全流程
git
海外空间恒创科技3 小时前
香港站群服务器与普通香港服务器对比
服务器·git·github
JinSo4 小时前
EasyEditor AI 聊天助手:让低代码开发更简单
前端·javascript·github
寻月隐君4 小时前
【Solana 开发实战】轻松搞定链上 IDL:从上传到获取全解析
后端·web3·github
Wetoria5 小时前
管理 git 分支时,用 merge 还是 rebase?
前端·git
ai小鬼头14 小时前
Ollama+OpenWeb最新版0.42+0.3.35一键安装教程,轻松搞定AI模型部署
后端·架构·github