报错:fetch first

简介

当我进行 git pull -u origin dev 时,报的错是:

 ! [rejected]        dev -> dev (fetch first)
error: failed to push some refs to 'https://gitee.com/'
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 同步代码,然后再推送

不推荐暴力推送:git push -f,这样会导致远程仓库同步成你的仓库文件,别人在最近更新而没有被你捕捉到的都会被覆盖。