git push报错: error: failed to push some refs to ‘[email protected]:xxx/xxx.git‘解决方法

git push的时候报错:

error: failed to push some refs to '[email protected]:xxx/xxx.git'

今天在把本地仓库push到远程仓库的时候,报错了。。。
就是这样:

git push报错: error: failed to push some refs to ‘git@github.com:xxx/xxx.git‘解决方法_第1张图片

或则是,使用 git gui 使用情况就是这样:

Pushing to git@github.com:************.git
To github.com:************.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to '************.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.

 
  
  
 
查了几种解决方式都不太管用,最后发现是由于github 中的 README.md文件 不在本地代码目录中

检查了一下果然如此!

这时候可以通过 git pull --rebase origin master README.md文件克隆到本地库。

 
  
 
git push报错: error: failed to push some refs to ‘git@github.com:xxx/xxx.git‘解决方法_第2张图片

之后可以看到本地仓库中有 README.md 文件了~~

git push报错: error: failed to push some refs to ‘git@github.com:xxx/xxx.git‘解决方法_第3张图片

 
  
  
 
此时再执行 git push origin master 就可以完成上传到远程仓库的操作了
git push报错: error: failed to push some refs to ‘git@github.com:xxx/xxx.git‘解决方法_第4张图片

或使用git gui 来实现push:

git push报错: error: failed to push some refs to ‘git@github.com:xxx/xxx.git‘解决方法_第5张图片

最后:

git push报错: error: failed to push some refs to ‘git@github.com:xxx/xxx.git‘解决方法_第6张图片

参考:
(1):https://blog.csdn.net/qq_34842671/article/details/70916587
(2):https://blog.csdn.net/sinat_34937826/article/details/90512627

你可能感兴趣的:(Git)