git push出现Updates were rejected because the remote contains work that you do not have locally

git建立新的仓库步骤:

  1. git init //初始化仓库
  2. git add .(文件name) //添加文件到本地仓库
  3. git commit -m “first commit” //添加文件描述信息
  4. git remote add origin + 远程仓库地址 //链接远程仓库,创建主分支
  5. git push -u origin master //把本地仓库的文件推送到远程仓库

第五步结束后出现错误:
git push出现Updates were rejected because the remote contains work that you do not have locally

解决方法

在第四步和第五步之间加一步就可以了:

git pull origin master // 把本地仓库的变化连接到远程仓库主分支

如果执行上面代码出现下面错误
git push出现Updates were rejected because the remote contains work that you do not have locally

1、当出现上述情况,可按键盘左上角的“Ese”退出键;
2、也可以输入“:wq”,注意是英文输入状态下的冒号,然后按下“Enter”键即可。