git连接到github报错的问题

git上传文件到GitHub报错: Updates were rejected because the tip of your current branch is behind的解决方法

步骤如下:

如果在第一步中创建时已经初始化过项目,则这时会提醒 error: failed to push some refs to ‘https://github.com/yourname/test.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文件了,所以需要先pull下来。命令如下: $ git pull origin master

这时又会报错:fatal: refusing to merge unrelated histories
说这两个库有不相干的历史记录而无法合并,这时我们可以加上一个参数 --allow-unrelated-histories 即可成功pull: $ git pull origin master --allow-unrelated-histories

注意:

但是这时会可能会提示必须输入提交的信息,默认会打开vim编辑器,先按 i 切换到插入模式,写完后 Esc→:→wq 即可保存退出编辑器。如果不进入vim编辑器,则会自动生成一个合并代码的commit。然后再使用前面的命令push将本地提交推送到远程仓库。

后面如果本地还有commit,就可以直接用 git push origin master 推送。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值