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

最终成功

相关推荐
大家的林语冰13 小时前
《前端周刊》React 败北,虾皇登基,OpenClaw 勇夺 GitHub 第一开源软件
前端·javascript·github
ShineWinsu14 小时前
对于Linux:git版本控制器和cgdb调试器的解析
linux·c语言·git·gitee·github·调试·cgdb
zhensherlock15 小时前
Protocol Launcher 系列:Microsoft Edge 浏览器唤起的优雅方案
javascript·chrome·microsoft·typescript·edge·github·edge浏览器
嗡嗡嗡qwq16 小时前
【如何使用vscode+github copilot会更加省额度】
vscode·github·copilot
php_kevlin16 小时前
git提交限制规范
大数据·git·elasticsearch
安大小万16 小时前
Git 常用命令终极指南:从入门到进阶
git
摇滚侠16 小时前
GIT 代码冲突 git pull 和 git pull rebase 的区别,保持提交记录的线性整齐
git
汪海游龙16 小时前
03.25 AI 精选:Wine 11重写内核层提速跑Windows游戏
github
研究点啥好呢17 小时前
3月24日GitHub热门项目推荐|让AI无所不能
人工智能·python·开源·github
Timer@17 小时前
TypeScript + React + GitHub Actions:我是如何打造全自动化 AI 资讯系统的 - 已开源
react.js·typescript·github