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

最终成功

相关推荐
摆烂菜鸡沧99611 分钟前
【自用整理】本地关联GitHub多账号设置
git·github
yuanyuan2o233 分钟前
Transformers NLP 任务:阅读理解问答
人工智能·算法·自然语言处理·nlp·github
nebula-AI34 分钟前
Understand Anything 简要使用文档
人工智能·ai·github·项目管理·知识图谱·dashboard
MicrosoftReactor36 分钟前
技术速递|使用 GitHub Copilot CLI 构建 Emoji 列表生成器
ai·github·copilot·cli
lisanmengmeng1 小时前
工作中的Git使用实践(三)
git
带娃的IT创业者2 小时前
1-Click GitHub Token Stealing:深入解析 VSCode 中的惊险漏洞
ide·vscode·github·安全漏洞·github token·1-click
lauo2 小时前
ibbot手机:一部手机,双重革命
人工智能·智能手机·架构·开源·github
东北甜妹15 小时前
GitLab配置步骤
git
JavaGuide17 小时前
Claude Code 怎么学?推荐 4 个高质量开源教程,从入门到实战
github·ai编程·claude
我命由我1234518 小时前
Android 开发问题:Could not find com.github.PicnicSupermarket:FingerPaintView:1.2.
android·github·android studio·安卓·android jetpack·android-studio·android runtime