git无法pull仓库

在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即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值