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

最终成功

相关推荐
逛逛GitHub1 小时前
GitHub 又一个 3D 人体可视化项目,AI 能力提升催生新场景。
github
峰向AI1 小时前
多代理协作的正确姿势:Atlas让 Claude Code 和 Codex共享记忆
github
菠萝加点糖1 小时前
Git 删除远程文件、本地保留并取消跟踪
git
蜡台2 小时前
GitHub 关闭 Two‑factor authentication(2FA)
github
HaipengYu4 小时前
Star History 凉凉?5 分钟部署一套属于自己的 GitHub 星标统计服务
github
理智.6294 小时前
Git 工具使用之项目版本回退与修改备份:stash、reset、reflog 常用指令详解
git·gitee·github
尚雷55806 小时前
避坑指南:从零搭建 openGauss oGRAC 双节点集群,这些细节要注意
github·ograc
妙码生花7 小时前
GIT 提交规范
git
TunerT_TQ8 小时前
GitHub每日热评|用写HTML的方式生成确定性MP4:HeyGen开源的HyperFrames到底强在哪?
开源·github·资讯
楠楠子呀9 小时前
给 GitHub Pages 这类纯静态站加 WhatsApp 入口:三种不引后端的写法
github