一、git push时报错
error: failed to push some refs to ‘git@gitee.com:Hotcocoa_Dq/helloworld.git’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.
二、问题分析
先到github上看看远程repository下到底有啥东西,发现目标库是空的。
但是有一个README.md文件(本地代码中没有),而出现错误的原因是github中的README.md文件不在本地代码目录中。
也就是说我们需要先将远程代码库中的任何文件先pull到本地代码库中,才能push新的代码到github代码库中。
三、解决问题
- 将远程代码库中的代码pull到本地代码库,并且执行合并merge:
$ git pull --rebase origin master
- 再次push代码:
$ git push -u origin master
至此问题解决。