1、错误反馈如下
木羽@yollose MINGW64 ~/Desktop/tmp (master)
$ git push origin master
To github.com:yollose/new.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:yollose/new.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
2、产生原因:
git不允许合并两个没有公共基础的仓库,本地仓库和远程仓库出现了冲突,一般在github中创建远程仓库时添加README.MD
会出现。
3、解决方案:
$ git pull origin master --allow-unrelated-histories
添加--allow-unrelated-histories
,让git忽略两仓库的历史,强行合并
合并后代码:
木羽@yollose MINGW64 ~/Desktop/tmp (master)
$ git pull origin master --allow-unrelated-histories
From github.com:yollose/new
* branch master -> FETCH_HEAD
Auto-merging 1.txt
Merge made by the 'recursive' strategy.
.gitignore | 330 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1.txt | 2 +
2 files changed, 332 insertions(+)
create mode 100644 .gitignore
4、防范措施
可以考虑在创建github远程仓库时,不选择添加README.MD
。或者直接使用git clone
来使用远程仓库
5、参考链接
其他解决方案:github上的版本和本地版本冲突的解决方法