第一次本地git push到远程仓库的时候出现 Updates were rejected because the remote contains work that you do not

文章讲述了用户在尝试将本地Gitmaster分支推送到Gitee远程仓库时遇到的问题,由于远程仓库有未合并的更改,解决方法包括清理远程别名、检查并拉取远程更新,以及使用`gitpush--allow-unrelated-histories`强制推送。
摘要由CSDN通过智能技术生成

🎯🎯🎯问题描述:

在这里插入图片描述命令中的duzhongbo就是我远程地址的别名,也就是下面这条命令起到的效果
git remote add duzhongbo https://github.com/WuPeiqi/pondo.git
当然后面这个地址并不是我的,举个例子
报错的错误:

error: failed to push some refs to 'gitee.com:du-zhongbo202024/epositoryp.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.

这个问题是将本地的 master 分支推送到远程 Gitee 仓库时,远程仓库已经有了你本地仓库所没有的提交

看到的解决办法是将远程仓库中的内容直接拉到工作区中就好了,于是我试了:

$ git pull duzhongbo1 master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 1.82 KiB | 372.00 KiB/s, done.
From https://gitee.com/du-zhongbo2020260724/program_tool_repositoryp
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> duzhongbo1/master
fatal: refusing to merge unrelated histories

还是不行,下面是另外成功的操作,供参考:

首先为了解决地址别名气的太多的情况,先把全部别名清空咱重新来一遍,不行你过来打死我😁😁😁

开始🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹

  1. 首先查询一下所有为远程地址起过别名
git remote -v

在这里插入图片描述

  1. 全部删掉,重新开始
git remote remove 别名

直到再次使用git remote -v 查询是不显示任何内容为止!
3. 重新开始,拷贝下仓库的ssh
使用下面语句为仓库的远程地址取别名:

git remote add origin git@gitee.com:du-zhongbo2020260724/program_tool_repositoryp.git
  1. 查询一下是否成功
git remote -v
origin  git@gitee.com:du-zhongbo2020260724/program_toryp.git (fetch)
origin  git@gitee.com:du-zhongbo2020260724/prepositoryp.git (push)

显示上面信息就是成功,有两个url是没错的。
在Git中,每个远程仓库都有两个URL关联,一个是fetch URL,另一个是push URL。这两个URL在git remote -v命令的输出中体现,分别用于不同的操作:

fetch URL: 这个URL是当你执行git fetch、git pull等命令时,Git用来从远程仓库获取数据的地址。当你需要从远程仓库获取最新的提交、分支或者其他资源时,Git会连接到这个地址。

push URL: 这个URL则是当你执行git push命令时,Git用来将本地提交推送到远程仓库的地址。当你想要分享本地的改动到远程仓库,使其他人能访问到你的更新时,Git会使用这个地址。

通常情况下,fetch和push URL是相同的,除非为同一个远程仓库设置了不同的fetch和push地址。这样做的好处是可以针对拉取和推送分别配置不同的访问策略,比如不同的访问凭据或者不同的访问路径。

  1. 将本地内容push上去
    这个时候用git push origin master将版本库中master分支上的内容推到远程地址别名为origin的地址时还是报了一下问题:
error: failed to push some refs to 'gitee.com:du-zhongbo2020260724/program_tool_repositoryp.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

ok那我们pull一下:git pull origin master
结果有fatal: refusing to merge unrelated histories
okok,放大招吧娘的…

  1. push
git push origin master --allow-unrelated-histories

然后就发现推成功了。

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江南霹雳堂雷家雷无桀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值