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

最终成功

相关推荐
ASEpochs44 分钟前
Vsocde中‘sh’不是内部或外部命令,也不是可运行的程序或批量处理文件--已解决
git·vscode·bash
coding消烦员1 小时前
在 Windows 内网搭建 Git 仓库:共享普通仓库 vs 中心 bare 仓库
windows·git
李@十一₂⁰2 小时前
git多分支管理
大数据·git·elasticsearch
爱写代码的派大星3 小时前
git 拉取和合并
git
想用offer打牌3 小时前
一站式讲清Spring AI Alibaba的OverAllState和RunnableConfig
人工智能·架构·github
Kp独立开发5 小时前
开源项目二次开发最佳实践:Fork + 分支隔离与同步
git·开源
逛逛GitHub6 小时前
推荐 5 个小众但有趣的 GitHub 开源项目。
github
极智-9966 小时前
GitHub 热榜项目 · 日榜精选(2026-01-07) | protobuf、web-check、PowerToys等
github·开发工具·开源项目·数据交互·ai框架
Tfly__8 小时前
Ubuntu20.04安装Genesis(最新)
linux·人工智能·pytorch·ubuntu·github·无人机·强化学习
程序员的程8 小时前
我做了一个前端股票行情 SDK:stock-sdk(浏览器和 Node 都能跑)
前端·npm·github