第一次git push代码报错:Push master to origin/master was rejected

为什么会有这样的问题?

这个问题一般发生在刚刚创建的远程仓库,在第一次git push的时候会发生。网上的说法是因为是第一次提交,远程仓和本地的代码相差太大,所以远程仓拒绝了提交的请求(但是本地的代码不是从远程仓下载的吗?怎么就相差大了?)
根据这个思路,肯定是要同步下远程仓,使本地仓跟远程仓一致。

怎么解决?

三条命令:
git pull
git pull origin master
git pull origin master --allow-unrelated-histories
然后再git push

tudou@LAPTOP-0KSP7OEO MINGW64 /d/work/sourceCodeGit/xcsl (master)
$ git pull
Already up to date.

tudou@LAPTOP-0KSP7OEO MINGW64 /d/work/sourceCodeGit/xcsl (master)
$ git pull origin master
From http://202.102.101.217:60360/zwfw/xcsl
 * branch            master     -> FETCH_HEAD
Already up to date.

tudou@LAPTOP-0KSP7OEO MINGW64 /d/work/sourceCodeGit/xcsl (master)
$ git pull origin master --allow-unrelated-histories
From http://202.102.101.217:60360/zwfw/xcsl
 * branch            master     -> FETCH_HEAD
Already up to date.

tudou@LAPTOP-0KSP7OEO MINGW64 /d/work/sourceCodeGit/xcsl (master)

你可能感兴趣的:(第一次git push代码报错:Push master to origin/master was rejected)