$ git push -u origin master
To https://gitee.com/****/spring-cloud-*****-study.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/****/spring-cloud-****-study.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.

git推送本地代码去新创建的远程仓库失败。
原因
在创建仓库的时候勾选了“使用Reamdme文件初始化这个仓库”。它会帮我们做一次初始提交,然后仓库就生成了README.m和.gitignore文件。当我们把本地项目关联到这个仓库把项目推送到仓库时,两端都是有内容的,但是这两份内容并没有联系。所以当我们推送到远程或者从远程拉取内容时,都会提示是没有被跟踪的内容,git报的提示中会让你先拉取再推送,但是拉取总是失败。
解决方法
git fetch origin
git merge origin/master //如果提示fatal: refusing to merge unrelated his

当在GitHub上新建并初始化了一个带有README的仓库,尝试将本地项目推送到该仓库时,由于两边都有初始内容,导致推送失败。解决办法是在git提示合并分支的编辑框中输入“:wq”退出编辑,然后正常推送。

674

被折叠的 条评论
为什么被折叠?



