问题信息:
当我们将本地代码上传至服务器时,git push -u origin master
报如下错误信息
问题原因:在新建的仓库的时候,勾选了README.md, 远程仓库的README.md不在本地仓库中.(同理,如果远程仓库中具有的文件,本地仓库没有,就会有冲突,此时就需要去合并)
$ git push -u origin masterTo http://xxxxxxxxx/xxxxx/xxxx.git! [rejected] master -> master (fetch first)error: failed to push some refs to 'xxxxxxxxx/xxxxx/xxxx.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决方案:
git pull --rebase origin master
$ git pull --rebase origin masterwarning: no common commitsremote: Enumerating objects: 3, done.remote: Counting objects: 100% (3/3), done.remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0Unpacking objects: 100% (3/3), done.From http://xxxxxxxx/xxxxxxx/xxxx.git* branch master-> FETCH_HEAD* [new branch]master-> origin/masterFirst, rewinding head to replay your work on top of it...Applying: first commit
然后再重新git push -u origin master