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

最终成功

相关推荐
向上的车轮2 小时前
GitHub Actions 自动化运维实战:Rust 全栈项目 CI/CD 至华为云
运维·自动化·github
互联网中的一颗神经元3 小时前
19 — 贮藏与清理:stash 是抽屉,gc 是打包箱
git
MicrosoftReactor4 小时前
技术速递|GitHub Copilot App 中的堆叠会话与拉取请求
ai·github·copilot·agent
dong_junshuai5 小时前
每天一个开源项目#67 Orca:4.3万星的并行 AI 编程控制台
程序员·开源·github
用户330144867635 小时前
20 — 远程进阶:强制推送的保险绳——force-with-lease
git
Cooper255 小时前
别急着改 Git 历史:rebase、cherry-pick、bisect 与 reflog 的安全操作顺序
git
峰向AI6 小时前
AI 画图要好看,还是要可信?小孩子才做选择,我两个都要!
github
刚入门的大一新生6 小时前
Linux-版本控制器Git
git
扶苏10026 小时前
同一个 Git 项目整出两份,切分支互不影响?两种方案实测
大数据·git·elasticsearch
ZJU_统一阿萨姆7 小时前
【Git】Github 开源许可证详解
git·开源·github