解决 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 陕西

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 你的mentor是什么样的人? #
4096次浏览 29人参与
# 你觉得mentor喜欢什么样的实习生 #
10394次浏览 288人参与
# 平安产险科技校招 #
2412次浏览 0人参与
# 帮我看看,领导说这话什么意思? #
6307次浏览 26人参与
# 没有家庭托举的我是怎么找工作的 #
12412次浏览 158人参与
# 怎么给家人解释你的工作? #
1425次浏览 16人参与
# 智慧芽求职进展汇总 #
17999次浏览 106人参与
# 求职低谷期你是怎么度过的 #
5263次浏览 92人参与
# 26届秋招公司红黑榜 #
12326次浏览 43人参与
# 从哪些方向判断这个offer值不值得去? #
6600次浏览 93人参与
# 同bg的你秋招战况如何? #
158823次浏览 927人参与
# 度小满求职进展汇总 #
10109次浏览 51人参与
# 实习必须要去大厂吗? #
146666次浏览 1541人参与
# 校招泡的最久的公司是哪家? #
4576次浏览 22人参与
# 你有哪些缓解焦虑的方法? #
37177次浏览 835人参与
# 面试紧张时你会有什么表现? #
1705次浏览 21人参与
# 你喜欢工作还是上学 #
77583次浏览 860人参与
# 入职第一天,你准备什么时候下班 #
85482次浏览 467人参与
# 秋招想进国企该如何准备 #
97710次浏览 487人参与
# 简历无回复,你会继续海投还是优化再投? #
103582次浏览 819人参与
# 机械人的工作环境真的很差吗 #
25034次浏览 119人参与
# 独居后,你的生活是更好了还是更差了? #
28126次浏览 263人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务