如何解决error: failed to push some refs to ‘xxx(远程库)‘(图文解说简洁版)

第一次在上传远程仓库的时候出现此问题:error: failed to push some refs to 'https://gitee.com/zhang-bingqian/crm.git'该怎么解决?


问题

D:\ideaProject\crm\crm>git push -u origin master
To https://gitee.com/zhang-bingqian/crm.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/zhang-bingqian/crm.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.

问题看图欣赏:
在这里插入图片描述

解决方案:

因为问题的可能出现在出现在oschina中的README.md文件不在本地代码目录中,所以我们需要本地也有,不然的话就会冲突。可以解决的方案应该你已经明白了。使用的是直接加入参数-f也可以,但是太过于粗暴,后果可能会什么都同步同步,一般不建议这样。那么最简单的方法如下

1. git pull --rebase origin master
看效果:
在这里插入图片描述

  1. git push -u origin master
    看看是否成功呢?
    在这里插入图片描述
    ok!成功了
posted @ 2022-05-07 16:07  诗风雅韵  阅读(444)  评论(0编辑  收藏  举报