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

最终成功

相关推荐
zhensherlock5 小时前
Protocol Launcher 系列:Trello 看板管理的协议自动化
前端·javascript·typescript·node.js·自动化·github·js
YoseZang5 小时前
【手工】git的使用 – 使用git进行项目协作
git
惺忪97987 小时前
git 多个branch对多个版本进行管理
git
夜瞬9 小时前
Git工作流程与常用指令——从本地开发到远程协作
大数据·git·elasticsearch
FEF前端团队10 小时前
开发知识库 #01:Git 全面操作教程
git·github
栩栩云生10 小时前
x-cmd v0.8.15: claw AI 助手升级,连微信、飞书更稳了;free 新增专家模式,直接把底层内存细节喂给你
github·agent·命令行
傻啦嘿哟11 小时前
Python 文件批量处理:重命名/备份/同步运维实战指南
linux·数据库·github
淘矿人12 小时前
Claude辅助算法设计与优化
人工智能·python·算法·microsoft·github·bug·pygame
逛逛GitHub12 小时前
给 10 万 Star 的 Hermes 装个记忆外挂,AI 终于能越用越聪明了。
github
王莎莎-MinerU13 小时前
MinerU 生态全接入:LangChain、Dify、RAGFlow、LlamaIndex 六大框架完整集成指南(2026)
计算机视觉·chatgpt·langchain·pdf·github·aigc