解决 error: failed to push some

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即可。

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

注意:距离上次push提交至今,在本地库commit的记录均暂存为patch。

#彻底拿下git#
全部评论
感谢大佬的分享
点赞 回复 分享
发布于 2022-10-21 19:51 陕西

相关推荐

06-04 18:37
门头沟学院 Java
勇敢的ssr求对象:前面看的有点奔溃,看到只有你是真玩啊,忍不住笑出了声😂
点赞 评论 收藏
分享
求面试求offer啊啊啊啊:把华北改为华南再试一试,应该就没啥问题了。改完可能都不用投,别人主动联系了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务