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

最终成功

相关推荐
Liu.7741 天前
vscode使用git和svn
git·vscode·svn
longze_71 天前
git凭证失效,CNB git credential 凭证突然失效
git
irpywp1 天前
autoresearch:自主目标导向迭代的无限游戏
开源·github·karpathy·autoresearch
汪海游龙1 天前
03.19 AI 精选:开源异步编程 Agent 框架
github·hacker news
NocoBase1 天前
【教程】用 NocoBase 2.0 搭建一个极简的 IT 工单系统
人工智能·开源·github·无代码
sandwu1 天前
OpenClaw 3.13 正式发布:新增 Chrome DevTools MCP、会话绑定、插件生态全面升级
人工智能·github
prince051 天前
git提交错了?直接删除提交记录
git
console.log('npc')1 天前
git代码冲突reset,如何回退到冲突之前提交之前的版本
javascript·git·react.js
无限进步_1 天前
【C++】获取字符串最后一个单词长度的多种解法
开发语言·c++·ide·windows·git·github·visual studio
程序员柒叔1 天前
Dify 版本追踪 - 2026-W12
人工智能·github·工作流·dify