push时git报错 error: failed to push some refs to 'git@gitee.com:git_zn/jianli.git' 解决办法

完整的错误提示如下

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 bash输入下面命令

git pull gitee master --allow-unrelated-histories

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

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

:wq

 

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

 

看到这个提示表明pull完成

 

再试试用

 

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

 

 

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

 


 

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

 


 

 

错误解决办法参考了廖雪峰老师的一篇文章: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/00150154460073692d151e784de4d718c67ce836f72c7c4000

 

posted @ 2018-08-22 15:31  大彪哥55  阅读(16161)  评论(1编辑  收藏  举报