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

最终成功

相关推荐
第一程序员31 分钟前
Python基础学习路径:非科班转码者的入门指南
python·github
badhope3 小时前
概率论如何让机器学习不再玄学
人工智能·深度学习·机器学习·数据挖掘·github
evan20203 小时前
faster-whisper 音频转字幕 懒人整合包
github
IT WorryFree4 小时前
如何设置微信群机器人
微信·github
Risehuxyc5 小时前
github里README和*.md的编写规则
github
badhope5 小时前
10个高星GitHub项目推荐
python·深度学习·计算机视觉·数据挖掘·github
春日见5 小时前
GIT操作大全(个人开发与公司开发)
开发语言·驱动开发·git·matlab·docker·计算机外设·个人开发
徐小夕6 小时前
花了一周时间,我们开源了一款PDF编辑SDK,支持在线批注+脱敏
前端·vue.js·github
逛逛GitHub6 小时前
让你的 Claude Code 起飞的 5 个小技巧,我用的很爽。
github
Ama_tor6 小时前
将本地的 Electron 项目上传到 Gitee(码云)的 Git 操作流程
git·electron·gitee