在github上新建了一个仓库并readme.md初始化,然后想要把本地一个已存在的仓库关联到这个远程库出现问题
$ git push -u github master
To github.com:***/learngit.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:***/learngit.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.
出现错误是因为远程有readme.md,和本地仓库没有关联,尝试再次重新创建仓库但是不用readme.md初始化,即可正常推送。
要解决此问题,根据提示git pull
$ git pull
fatal: No remote repository specified. Please, specify either a URL or a
remote name from which new revisions should be fetched.
还是有问题,再根据提示:
$ git pull github master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:***/learngit
* branch master -> FETCH_HEAD
+ b41eff5...7aa37d7 master -> github/master (forced update)
fatal: refusing to merge unrelated histories
错误:fatal: refusing to merge unrelated histories
那么我们 需要这样写git pull github master – –allow-unrelated-histories
最后再push即可。