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

最终成功

相关推荐
SiYuanFeng7 小时前
新手学Git:如何把本地 Git 项目上传到 GitHub
git·github
前端若水8 小时前
git回退并合并分支操作
git
桌面运维家12 小时前
中小学IDV云桌面vDisk挂载部署方案
github
MXN_小南学前端13 小时前
Vue3 + Spring Boot 工单系统实战:用户反馈和客服处理的完整闭环(提供gitHub仓库地址)
前端·javascript·spring boot·后端·开源·github
程序员鱼皮14 小时前
Git WorkTree 是什么?凭什么能让 AI 编程效率翻倍?
git·ai·程序员·编程·ai编程
lentoo-14 小时前
GitHub 暂停了 Copilot 付费注册
github·copilot
一颗青果14 小时前
Cookie 与 Session 超详细讲解
服务器·前端·github
懵逼的小黑子16 小时前
git与远程仓库创建连接
git
skywalk816316 小时前
为aicomm项目添加CI/CD 配置 让github帮我们自动测试
ci/cd·github
Yunzenn16 小时前
零基础复现Claude Code(五):终端篇——赋予执行命令的超能力
面试·github