背景
本地git庫,要push到gitlab上,執(zhí)行完如下命令后報錯:
git push origin master
報錯信息為:
![rejected] master -> master(non-fast-forward)
error:failed to push some refs to XXX
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.
原因
從本地代碼創(chuàng)建遠程倉庫的時候,添加了README.md,但本地倉庫中并沒有該文件。
解決方案
添加忽略不相干的歷史選項,將遠程倉庫中的文件重新拉取到本地,這樣本地文件會出現(xiàn)README.md:文章來源:http://www.zghlxwxcb.cn/news/detail-756017.html
git pull origin master --allow-unrelated-histories
之后再正常推送:文章來源地址http://www.zghlxwxcb.cn/news/detail-756017.html
git push origin master
總結(jié)
- 遠程倉庫在上傳的時候,添加了README.md文件,而本地沒有該文件,導(dǎo)致本地倉庫和遠程倉庫存在不同的commit,導(dǎo)致無法提交。
- 先創(chuàng)建遠程倉庫,然后clone到本地,再進行開發(fā)
- 遠程倉庫不添加README.md,如果有需要,本地新建后push到遠程倉庫即可
到了這里,關(guān)于git push報錯:![rejected] master -> master(non-fast-forward) error:failed to push some refs to XXX的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!