参考:https://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to
在码云新建了一个项目后生成有readme.md文件在push本地项目是出现一下错误
$ git push gitee master
To gitee.com:wei_1/Tess4JDemo.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@gitee.com:wei_1/Tess4JDemo.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.
原来是需要先合并远程master分支,于是执行pull命令
$ git pull gitee master
warning: no common commits
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From gitee.com:wei_1/Tess4JDemo
* branch master -> FETCH_HEAD
* [new branch] master -> gitee/master
fatal: refusing to merge unrelated histories
使用一下命令可以,上面连接上的为什么我没看太懂。。
The full syntax is:
git pull --rebase origin master
git push origin master
That way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch: git pull origin yourBranch).
使用git pull --rebase origin master
即可