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

最终成功

相关推荐
Bryan_Long3 小时前
Git 命令行操作提交至远程仓库
git·github
muyouking113 小时前
3.Rust + Axum 提取器模式深度剖析
前端·rust·github
小华同学ai4 小时前
15.4K Star!Vercel官方出品,零基础构建企业级AI聊天机器人
github
微臣愚钝4 小时前
git的上传流程
git
lmxnsI4 小时前
git报错
git
三道杠卷胡5 小时前
【AI News | 20250417】每日AI进展
人工智能·pytorch·python·语言模型·github
bulucc5 小时前
回归,git 分支开发操作命令
大数据·git·elasticsearch
岳轩子7 小时前
git更新的bug
git·bug
绝无仅有8 小时前
使用 Docker 安装 Elastic Stack 并重置本地密码
后端·面试·github
uhakadotcom8 小时前
Langflow:零基础快速上手AI流程可视化开发工具详解与实战案例
后端·面试·github