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

最终成功

相关推荐
xiaoxiang960925 分钟前
Git 分支同步实战:`merge -X theirs` 与完全合并方案
数据库·git·elasticsearch
用户693717500138429 分钟前
前阵子刷屏的 Ox-Alpha 真身揭晓!GLM-5.3-Flash 上线,这价格真的杀疯了
前端·后端·github
李可以量化2 小时前
Redis Client 从了解到精通(二)下:String 类型进阶操作全解
redis·git·python·量化交易·qmt
wy3136228212 小时前
Git——ignore让项目的 target 目录真正被忽略(忽略其他文件也是同样的道理)
开发语言·git
浪潮行舟2 小时前
使用 Notion 和 GitHub 构建知识库系列一
github·notion
deli0070073 小时前
正则表达式可视化测试工具:输入即匹配,高亮一目了然
git·测试工具·正则表达式
爱莉希雅&&&3 小时前
Git 版本控制完整学习笔记
笔记·git·学习
用户813267933255 小时前
Python 计算盘中 VWAP:为什么 1 分钟 K 线是量化工程中的高性价比选择
后端·算法·github
高频因子挖掘机5 小时前
Python批量获取1000只ETF 5分钟K线:从分页到吞吐量优化的QuantDash实践
后端·算法·github
苏灿烤鱼6 小时前
一个 1.7 万 Star 的开源项目,教我们怎么判断 AI 工具值不值得用
html·github·agent