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

最终成功

相关推荐
running up5 小时前
Github 首页美化教程
github
草梅友仁10 小时前
草梅 Auth 1.12.0 发布与墨梅博客立项经验 | 2025 年第 50 周草梅周报
开源·github·ai编程
一勺-_-12 小时前
.git文件夹
大数据·git·elasticsearch
雪域迷影12 小时前
Windows11中使用VS2022编译运行libevent网络库
网络·github·cmake·visual studio·libevent
likeshop 好像科技14 小时前
新手学习AI智能体Agent逻辑设计的指引
人工智能·学习·开源·github
TT哇14 小时前
【git】本地代码上传到gitee仓库(保姆级教程)idea和vscode等通用
git·gitee·intellij-idea
人在旅途我渐行渐远14 小时前
idea 通过git撤销commit但未push的操作
java·git·intellij-idea
Serene_Dream14 小时前
IDEA中多人项目中如何将自己的本地分支调整到远程的最新分支下
git·github
中冕—霍格沃兹软件开发测试15 小时前
Git版本控制在测试项目管理中的应用
人工智能·git·科技·开源·appium·bug
分布式存储与RustFS16 小时前
MinIO替代方案生态集成指南:RustFS如何无缝融入现代技术栈
rust·github·开源项目·对象存储·minio·企业存储·rustfs