Git推送问题解决——(rejected)本地仓库未同步远程更新

        这是在git推送中遇到的一个典型问题,在这里给大家总结一下,给大家做一个问题解决的例子(解决方法有很多,这里只展示最推荐的办法)。

        我在主分支上提交,push时出现如下报错:

$ git push -u origin main
To github.com:xxxxx/xxxx.git
Merge branch 'main' of github.com:xxxxx/xxxx
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com:xxxxx/xxxx.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

        根据错误信息可知,在本地进行开发并尝试推送代码到远程仓库时,远程仓库已经被其他开发者推送了新的代码。Git 为了防止我的推送覆盖远程仓库的最新更改,拒绝了我的推送操作。

        这种情况下,我需要先将远程仓库的更改拉取到本地,然后再进行推送。

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值