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

最终成功

相关推荐
Dawn·张7 小时前
Unity小:GitHub部署静态网页
github
玖玖passion10 小时前
Windows 上部署 Hermes Agent 完整指南 - 让你的 AI 助手在 WSL2 中跑起来
前端·后端·github
AC赳赳老秦11 小时前
OpenClaw实战案例:用Agent实现每日工作日报自动生成+发送
人工智能·python·职场和发展·eclipse·github·deepseek·openclaw
Hommy8813 小时前
【开源剪映小助手】调试与故障排除
开源·github·aigc
摆烂z13 小时前
AI同时完成多个功能(Git WorkTree)
git
CoderJia程序员甲14 小时前
GitHub 热榜项目 - 日榜(2026-04-24)
人工智能·ai·大模型·github·ai教程
___波子 Pro Max.18 小时前
Git Worktree 可视化理解指南
git
AI技术增长19 小时前
第 2 集:环境搭建:安装 Claude Code、GitHub CLI 与项目初始化
人工智能·自动化·github
happymaker062620 小时前
git使用快速入门
git
MuzySuntree20 小时前
Ubuntu 使用 GitHub SSH 克隆时报 Permission denied (publickey) 解决方案
ubuntu·ssh·github