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

最终成功

相关推荐
℘团子এ8 分钟前
git中,项目怎么更换远程仓库连接地址
git
念丶小宇4 小时前
Github上传大文件
github
言之。6 小时前
Git Hooks
git
代码AI弗森7 小时前
Git Bash 与 PowerShell:定位差异、使用场景与选择建议
开发语言·git·bash
极智-9968 小时前
GitHub 热榜项目-日榜精选(2026-02-03)| AI智能体、终端工具、RAG技术等 | claude-mem、99、termux-app等
人工智能·网络安全·github·ai智能体·llm应用·rag技术·torrent工具
森叶8 小时前
Git flow command error: ‘flow‘ is not a git command 问题解决
git
骂我的人都死了9 小时前
DevOps架构部署
运维·ubuntu·docker·k8s·github·devops·python3.11
Alaaaaaaan9 小时前
[DevOps]使用github-action工具部署docker容器(实现提交代码一键推送部署到服务器)
服务器·前端·docker·容器·github
天麓9 小时前
git merge 举例
git
CryptoRzz10 小时前
德国股票数据 API 对接实战(DAX 指数与实时行情)
websocket·区块链·github·分布式账本