Github-git pull解决远程与本地仓库的冲突

今天git push origin master的时候遇到了下面问题:

Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes(e.g. 'git pull ...')before pushing again.


后来查了下,才发现是这么一个问题:


一开始文件处于X,有一次我直接在github上对X进行了修改,也就是在远程仓库修改后从X到了A。但是这次修改我并没有同步更新到我的本地仓库,而此时我又将本地的仓库git push,就相当于要从X到B。而实际上远程仓库的A是比B先更新的,B所在的分支其实要在A之后,这样就产生了冲突。
因此在本地仓库push之前先要在本地合并远程的更新。
所以解决办法是先pull,即将远程仓库的更新下载更新到本地仓库。

    git pull <remote> <branch>

即将远程的某个分支down下来。

命令如下:
    git pull origin master
    git push origin master

搞定哈哈!!!

猜你喜欢

转载自blog.csdn.net/sunny_xsc1994/article/details/51152112