成功解决:Updates were rejected because the tip of your current branch is behind its remote...【解决方法】

一、报错发生

最近使用git,一直使用命令行操作。昨天突发奇想研究了一番git的GUI,结果由于操作不当产生了如下报错:

Updates were rejected because the tip of your current branch is behind its remote counterpart.

二、报错原因

该报错在git push时出现,一句话解释就是你在本地仓库上的修改没有基于远程库最新版本,本地仓库版本落后于远程仓库。这个报错告诉我们在本地开发的时候,要经常使用git pull获取远程分支最新改动,这样才能保证在最终git push的时候本地commit历史和远程commit历史是一致的。

或者,起初本地仓库和远程仓库是同步的,不过有多个人都在该分支上开发,另一个人在某一天做了修改并提交到远程库了。此时远程库和你的本地库就不同步了。后续同场景一。

三、解决方法

先pull一下:

git pull origin


再push:

git push origin main
git push origin master


接下来的继续正常操作即可。

猜你喜欢

转载自blog.csdn.net/Xuange_Aha/article/details/128603638