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

最终成功

相关推荐
用户3177230703629 分钟前
Pydub:用 Python 处理音频,不写废话
github
深海鱼在掘金33 分钟前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
张居邪1 小时前
GitHub Actions + 阿里云 OSS:OIDC 免密同步构建产物
后端·github
张居斜13 小时前
GitHub Actions + 阿里云 OSS:OIDC 免密同步构建产物
github·oss·llm-wiki
用户32283600844716 小时前
python-rapidjson:用 C++ 速度处理 JSON 的 Python 库
github
逛逛GitHub17 小时前
4 个比较实用的 GitHub 开源项目,浅浅的收藏一波。
github
Hommy8817 小时前
【剪映小助手】添加贴纸接口(Add Sticker)
后端·github·剪映小助手·视频剪辑自动化·剪映api
noravinsc20 小时前
关于Git Flow
git
2601_9618451520 小时前
粉笔行测5000题电子版|pdf|解析
pdf·新媒体运营·github·个人开发·内容运营·规格说明书·极限编程
蜜獾云21 小时前
在Git中配置用户名和密码
git