git--push失败解决方案

错误1

远程创建了含有Readme的仓库, 本地初始化并添加了远程仓库后, push却失败了, 出现提示:

$ git push origin dev

To https://git.oschina.net/erchoc/laradock.git

 ! [rejected]        dev -> dev (fetch first)

error: failed to push some refs to 'https://git.oschina.net/erchoc/laradock.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.

问题(Non-fast-forward)的出现原因是: git仓库中已有一部分代码, 它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:

1. 强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容: git push -f

2. 先把git的东西fetch到你本地然后merge后再push

    - $ git fetch
    - $ git merge

这2句命令等价于

$ git pull 

可是, 有时候还会出现问题:

上面出现的 [branch "master"]是需要明确(.git/config)如下的内容

[branch "master"]

    remote = origin

    merge = refs/heads/master

这等于告诉git2件事:

1,当你处于master branch, 默认的remote就是origin。

2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上所有的改变

如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:

$ git config branch.master.remote origin 

$ git config branch.master.merge refs/heads/master 

之后再重新git pull下。最后git push你的代码吧。

错误2

在使用git push时报出如下的错误:

$ git push -u origin master
fatal: HttpRequestException encountered.
   发送请求时出错。
Username for 'https://github.com':


在这里插入图片描述
都是同一个问题。
之前时不需要输入的,现在需要输入了,原因是git更新了一个证书,我们本地需要再更新以下:
https://github.com/microsoft/Git-Credential-Manager-for-Windows/releases
进去后点击下载安装 GCMW最新版即可:
在这里插入图片描述




[参考博客] 本文章是对以下两篇文章的拼接
https://www.jianshu.com/p/ea6ec80ad5f2?t=123
https://blog.csdn.net/qq_43442524/article/details/105951479

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值