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

最终成功

相关推荐
青红光硫化黑1 小时前
Git基础之基本操作
git
疏狂难除3 小时前
在github action工作流使用nw和nw-builder打包
github
熙曦Sakura6 小时前
【Git】创建,切换分支
git
lida20038 小时前
ArduPilot开源代码之AP_OSD
git·开源·ardupilot
Timbo2号10 小时前
OpenAI API调用实战:跨境支付验证的技术解决方案
人工智能·github
Hamm11 小时前
咦,你的Git仓库贡献者里怎么有这么多大佬???
前端·git·github
钢板兽12 小时前
Java后端高频面经——JVM、Linux、Git、Docker
java·linux·jvm·git·后端·docker·面试
uhakadotcom13 小时前
ClickHouse入门:快速掌握高性能数据分析
后端·面试·github
uhakadotcom13 小时前
Pydantic Extra Types:扩展数据类型的强大工具
后端·面试·github
uhakadotcom13 小时前
Spring Fu:让Spring Boot启动提速40%的黑科技
后端·面试·github