Git报错:解决This is usually caused by another repository pushing to the same ref.的错误

1.报错信息

当我们在IDEA中点击push按钮要将本地版本仓库推送到远程版本仓库gitee时候,常会出现以下报错信息:This is usually caused by another repository pushing to the same ref.

将该报错信息翻译为中文为:这是由于另一个存储库推送到同一引用而引起的。

2.分析报错

当我们在gitee或者github创建仓库时,不小心勾选了初始化该仓库的单选框,初始化仓库时,仓库内会自动创建README.m和.gitignore文件,系统会将这一举动作为第一次初始提交。然而当我们将本地版本仓库推送到远程版本仓库gitee时候,两端都是有内容的,而且这两端的内容没有联系,因此当我们对远程仓库进行操作(推送或拉取)时,均会存在没有被跟踪的文件内容。而报错中也提示说要先拉取,再推送,从而使两者建立联系。

3.解决报错

首先我们可以在该项目目录中,使用git pull --rebase origin master命令来拉取:

PS D:\Java\IDEA\workspace\shixun\ErrorTest> git pull --rebase origin master
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 1.87 KiB | 147.00 KiB/s, done.
From https://gitee.com/fxw0817/error-test
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Successfully rebased and updated refs/heads/master.

然后使用git push -u origin master命令上传代码

PS D:\Java\IDEA\workspace\shixun\ErrorTest> git push -u origin master
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 12 threads
Compressing objects: 100% (16/16), done.
Writing objects: 100% (26/26), 3.12 KiB | 3.12 MiB/s, done.
Total 26 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag ea4a26a6
To https://gitee.com/fxw0817/error-test
   f9985d3..8d84590  master -> master
branch 'master' set up to track 'origin/master'.

接下来代码就可以推送成功了。

4.当创建仓库时要保证仓库是一个空仓库,便可以避免这个问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值