当使用GitHub进行代码push是,出现了下面的错误,该如何是好?

错误描述:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Willido/First.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.
出错原因:

git仓库中已经有一部分代码,导致远程仓库中代码版本与本地仓库中的不一致,所以它不允许你直接把你的代码覆盖上去。

解决办法:

1)强推

强行上传,即利用强覆盖方式使用本地的内容去替代git仓库中的内容,命令如下:

$ git push -f

2)先下载再上传

a.先将git仓库中的内容fetch即下载到你本地中,然后再merge,命令如下:

$ git fetch
$ git merge

也可以直接pull,命令如下:

$ git pull

但此时将又会出现另外的问题,错误信息如下:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:
    [branch "master"]
    remote = <nickname>
    merge = <remote-ref>

[remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.
上面出现的 [branch "master"]是需要明确如下的内容(位于.git/config中)
[branch "master"]
    remote = origin

merge = refs/heads/master

这是要告诉git两件事:

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

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

可以手工编辑config文件,也可以在终端上进行命令行编辑,所需命令行如下:

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

b.然后再重新pull一下,命令行如下:

$ git pull

c.最后再进行push,命令行如下:

$ git push

GitHub--git push出错解决的更多相关文章

  1. [git/GitHub] git push 时报错:fatal: remote error: You can't push to git://github.com/user/xxx.git(已解决)

    当使用  git push  时,提示以下错误: fatal: remote error: You can't push to git://github.com/user/xxx.git Use ht ...

  2. git push出错的解决办法

    今天push代码到线上的时候怎么都不行,尝试了很多办法报了好几种错比如: 反正就是各种错,然后其实不管什么错,你全部Git init 一下然后重新配置 git config --global user ...

  3. Linux] Git: push 出错的解决 master -> master (branch is currently checked out)

      在使用Git Push代码到数据仓库时,提示如下错误: [remote rejected] master -> master (branch is currently checked out ...

  4. git push冲突解决

    1. 首先,可以试图用git push origin branch-name推送自己的修改:2. 如果推送失败,则因为远程分支比你的本地更新,需要先用git pull试图合并:如果git pull提示 ...

  5. Git push 出错 [The remote end hung up unexpectedly] - 简书

    one day,my teamate using git push and occured this error. $ git push Counting objects: 2332669, done ...

  6. [GitHub] git push的时候报错 fatal: unable to access 'http://github.com/xxx/xxx.git/': Recv failure: Connection reset by peer

    参考了两种方法: 1. 解决fatal: unable to connect to github.com问题 http://blog.csdn.net/greenqingqingws/article/ ...

  7. git命令行解决冲突文件步骤

    原文https://blog.csdn.net/zwl18210851801/article/details/79106448 亲测有用,解决git冲突的好办法 方法一(推荐使用): git pull ...

  8. git 报错:error: failed to push some refs to 'https://github.com/Anderson-An/******.git'(已解决)

    提交push 报错: $ git push origin masterTo https://github.com/Anderson-An/******.git ! [rejected] master ...

  9. (诊断)解决GitHub使用双因子身份认证“Two-Factor Athentication”后无法git push 代码的“fatal: Authentication failed for ...”错误

    在GitHub上采取双因子身份认证后,在git push 的时候将会要求填写用户的用户名和密码,用户名就是用户在GitHub上申请的用户名,但是密码不是普通登录GitHub的密码. 一旦采取双因子身份 ...

随机推荐

  1. js 鼠标上移 图片放大

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. centos6.5 中文

    之前在网上查了不少资料,很多网友在网上都说,在shell命令下输入:     # vi  /etc/sysconfig/i18n     然后修改LANG="en_US.UTF-8" ...

  3. [ionic开源项目教程] - 第8讲 根据菜单分类加载数据(重要)

    [ionic开源项目教程] - 第8讲  根据菜单分类加载数据(重要) [效果图] 注意 今天遇到一个比较棘手的问题,就是左右滑动菜单的设计不合理性,所以tab1.html对应的视图层和control ...

  4. 51nod1379 索函数

    果断打表找规律.然后看得出来是2^k-1之后又不知道怎么求出k有什么卵用... http://blog.csdn.net/guhaiteng/article/details/52094210 %%%% ...

  5. asp.net webpage

    一.服务器脚本基础介绍 首先,我们先复习一下Web服务器页面的基本执行方式: 1. 客户端通过在浏览器的地址栏敲入地址来发送请求到服务器端 2. 服务器接收到请求之后,发给相应的服务器端页面(也就是脚 ...

  6. iso中第三方框架SDWebImage的使用步骤

    一.SDWebImage的使用 1.依赖的框架 * ImageIO.framework * MapKit.framework 2.UIImageView下载图片需要的头文件:UIImageView+W ...

  7. mokoid android open source HAL hacking in a picture

    /************************************************************************** * mokoid android HAL hac ...

  8. python练习程序(c100经典例9)

    题目: 要求输出国际象棋棋盘. for i in range(1,9): for j in range(1,9): if i%2==0: if j%2==0: print '*', else: pri ...

  9. mysql,多表的内外连接+子查询

    表: student house course 关系:student_course 多对多 student house 多对一 需求:查询房间1 的学生 都学习了什么课程 select s.s_nam ...

  10. 【英语】Bingo口语笔记(77) - 临时改变计划的表达