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

8 篇文章 2 订阅
当尝试推送Git时遇到'failed to push some refs'错误,通常是因为远程库与本地库存在差异。解决方法是使用`git pull --rebase origin master`,先将远程库的更新合并到本地,再进行push。这会避免直接push导致的冲突,确保远程和本地保持同步。
摘要由CSDN通过智能技术生成
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。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

timerring

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值