github遇到的坑1

上午在local本地创建一个仓库,然后在github远端创建一个仓库,然后想将本地的仓库和远端的仓库连接起来,然后问题就出现了。
按照正常的github命令,先是
git remote add origin SSH Key
例如git remote add origin git@github.com:michaelliao/learngit.git
这一步没有问题,然后
git push -u origin master,就出现错误了。如下所示:

$ git push -u origin master
To git@github.com:******/Demo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to ...
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

从它的hint可以看出,Updates were rejected because the tip of your current branch is behind,当前分支没有和远程仓库同步,所以就找解决办法,然后有人说要
git pull --rebase origin master
这个指令没有错误,然后以为解决了,继续
git push -u origin master
又错了,但是错误原因不一样,具体的内容是说有conflict没有解决掉,然后解决方法之一是
git pull,但是意料之中报错了,

Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'

中间记不太清了,最后得到了下面这样子的一个错误:
error : you need to resolve your current index first
继续找解决办法,最后终于在@wenwenxiong的帮助下,找到了解决办法,大致原因是merge导致的:
解决半法就是直接退回merge前,然后再push,执行以下代码:

git reset --merge  

执行完这句话以后,后面的指令可以全部实现了,可以成功push到远程仓库了。


上面查找解决办法的过程中,有另外一种方法,但我没有试,写出来如下:

git push -u origin master -f   

也就是强行push,但是这样子多人一起开发的时候,就会出现别人的提交会被覆盖,一般不建议这么做。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值