Git:远程仓库名称变更本地无法提交解决

报错信息

bash 复制代码
blog % git push
To github.com:hannah-lin-sama/web-docs.git
 ! [rejected]        main -> main (non-fast-forward)
错误:无法推送一些引用到 'github.com:hannah-lin-sama/web-docs.git'
提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。
提示:再次推送前,先与远程变更合并(如 'git pull ...')。详见
提示:'git push --help' 中的 'Note about fast-forwards' 小节。

解决

bash 复制代码
# 删除远程仓库
git remote remove origin
bash 复制代码
git remote -v # 查看一下结果
bash 复制代码
# git@github.com:hannah-lin-sama/blog.git  远程仓库名称
git remote add origin git@github.com:hannah-lin-sama/blog.git 
bash 复制代码
# 分支 'main' 设置为跟踪 'origin/main'。
git branch --set-upstream-to=origin/main main
bash 复制代码
git pull

git pull 拉取代码报错,存在偏差分支

提示:您有偏离的分支,需要指定如何调和它们。您可以在执行下一次

提示:pull 操作之前执行下面一条命令来抑制本消息:

bash 复制代码
git config pull.rebase false  # 合并
bash 复制代码
# 拉取代码
git pull

# 中间有冲突解决冲突,后提交
# 推送代码
git push
相关推荐
徐子元竟然被占了!!14 小时前
Git学习
git·学习·elasticsearch
l1o3v1e4ding15 小时前
windows安装Claude Code,并接入Deepseek-v4模型 ,提供离线安装包
git·npm·node.js·claude code·cc-switchcc
Dontla1 天前
git bash打开Claude code报错:Claude Code on Windows requires git-bash.(别把git装其他位置,严格按照默认安装)找不到claude code
windows·git·bash
一个梦醒了1 天前
安装git bash选项推荐
开发语言·git·bash
呆萌的代Ma1 天前
Git不强行推送,撤销最近几次的提交
git
透明的玻璃杯1 天前
git应用
git
炸炸鱼.1 天前
Git+Jenkins实战(一):从零搭建自动化发布与回滚系统(附完整代码)
git·jenkins
言6661 天前
要忽略前端依赖包node_modules的文件在目录下 git暂存区消失
git
胡小禾2 天前
Git Worktree
git
程序员小羊!2 天前
18 GIt
git