宝塔服务器面板,一键全能部署及管理,送你10850元礼包,点我领取

在廖雪峰老师网站学习git教程(git教程地址)时,学到码云相关内容,发现使用git push origin master命令会报错,完整的错误提示如下

To gitee.com:git_zn/jl.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@gitee.com:git_zn/jl.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

根据错误提示 用git pull 将远程仓库的内容pull下来

无奈pull下来后再push还是报上述错误

码云使用git push时报错 error: failed to push some refs to ‘git@gitee.com…’ 解决办法-风君雪科技博客

网上查找资料 找到了下面的解决办法

在当前本地仓库下用git bash输入下面命令

git pull gitee master --allow-unrelated-histories

此时会有一个弹窗,提示你修改一个文档的内容,不用管他,按ESC键

再按SHIFT+;  (SHIFT+;用来输入一个冒号)  再输入wq保存

:wq

接下来git会把远程仓库再pull一次

码云使用git push时报错 error: failed to push some refs to ‘git@gitee.com…’ 解决办法-风君雪科技博客

看到这个提示表明pull完成

再试试用

 git push gitee master
  •  注意
    • git push gitee master  gitee是我的远程仓库名字已经被我修改了,默认的一般为origin

码云使用git push时报错 error: failed to push some refs to ‘git@gitee.com…’ 解决办法-风君雪科技博客

出现上面提示表示push到远程仓库成功


上面的错误我只在码云上遇到过,在github上还没有遇到这样的问题,解决的办法应该和上面的类似

本文作者:小宇宙55    原文链接:http://www.cnblogs.com/xiaoyuzhou55/p/9517987.html