相信大家使用git 推送到远端master分支的时候, 偶尔会碰到Updates were rejected because the remote contains work that you do
为什么会出现这个情况呢? 因为master分支(其他分支也是如此,这里以master举例)还没有和本地master分支建立关联,注意!出现这个现象,是因为我们只是建立了本地仓库与远端仓库的连接,然后用git clone拉下远端某分支代码(没有关联), 要推送到master分支, 必须跟master分支关联起来,总体步骤如下:
错误步骤:
1. git init //初始化仓库
2. git add .(文件name) || * //添加文件到本地仓库
3. git commit -m "xxxxxx" // 添加文件描述信息
4. git remote add origin 远程仓库地址url // 链接远程仓库,创建主分支
5. git push -u origin master // 把本地仓库的文件推送到远程仓库
正确步骤:
1. git init //初始化仓库
2. git add .(文件name) || * // 添加文件到本地仓库
3. git commit -m "xxxxxx" // 添加文件描述信息
4. git remote add origin 远程仓库地址url // 链接远程仓库,创建主分支
5. git pull origin master // 把本地仓库的变化连接到远程仓库主分支【重点步骤】
6. git push -u origin master // 把本地仓库的文件推送到远程仓库