error: failed to push some refs to 'git@github.com:

今天像往常一样进行git远程推送,在GitHub上的仓库是存在的,git push时结果出现以下报错:

$ git push -u origin masterTo git@github.com:xxx/xxx.git 
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:xxx/xxx.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 origin master

然后就看到了远程文件已经下载到你的工程里面并且自动合并了。

remote: Counting objects: 5, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 5 (delta 4), reused 5 (delta 4), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:xxxx/demo-test1
 * branch            master     -> FETCH_HEAD
   ffdc5ca..f30f5a3  master     -> origin/master
Auto-merging package.json
Auto-merging .idea/workspace.xml
CONFLICT (content): Merge conflict in .idea/workspace.xml
Automatic merge failed; fix conflicts and then commit the result.

如遇到merge failed根据提示git commit 操作就可以了。

接下来就可以正常在本地库中添加新文件并且提交,
最后,运行

 git push -u origin master

Done 成功!

    原文作者:andreaxiang
    原文地址: https://www.jianshu.com/p/72b5ebfce5b6
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞