问题描述
在idea中往码云推送新项目时报错:
error: failed to push some refs to ‘git@gitee.com:walln7/helloworld.git’
To gitee.com:walln7/helloworld.git
hint: Updates were rejected because the remote contains work that you do
! refs/heads/master:refs/heads/master [rejected] (fetch first)
hint: not have locally. This is usually caused by another repository pushing
Done
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.
原因分析
本地代码和远程仓库的代码存在冲突,导致推送失败。
问题解决
先从远程拉取代码(即使仓库是空的),再往远程推送代码。
命令行方式
- 在项目工作目录下打开Git命令行窗口,执行
git pull origin master --allow-unrelated-histories
,允许从远程拉取代码,并允许有不相关的历史记录。 - 往远程推送代码,执行
git push origin master
idea方式
- 拉取代码后出现:
- 选择branch
- 执行update