解决 error: failed to push some refs to ‘https://github.com/

Resolve error: failed to push some refs to '​​https://github.com/​

报错:

! [rejected] main -> main (fetch first) error: failed to push some refs to '​​https://github.com/XXX.git​​'

原因:远程库和本地库不一致。通常出现在初始化仓库有readme而本地没有等情况。

提示: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 --rebase origin master

原理:

把远程库中的更新合并到本地库中,–-rebase的作用是取消掉本地库中刚刚的commit,并把他们接到更新后的版本库之中。然后再进行push即可。

解决 error: failed to push some refs to 'https://github.com/

​git pull -–rebase origin master​​ 操作,意为先取消commit记录,并且把它们临时保存为补丁(patch)(这些补丁在”.git/rebase”目录中),之后同步远程库到本地,最后合并补丁到本地库之中。

发表评论

相关文章