当使用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. 利用SOLR搭建企业搜索平台 之——solr的查询语法

      1. 首先假设我的数据里fields有:name, tel, address 预设的搜寻是name这个字段, 如果要搜寻的数据刚好就是 name 这个字段,就不需要指定搜寻字段名称. 2. 查询规 ...

  2. Android内存管理(4)*官方教程 含「高效内存的16条策略」 Managing Your App's Memory

    Managing Your App's Memory In this document How Android Manages Memory Sharing Memory Allocating and ...

  3. Android Studio AVD和SDK Manager灰色不能点击的问题。

    之前安装完Android Studio之后,迫不及待的打开,新建项目,发现模板新建之后里面没有文件,并且AVD Manager和SDK Manager 那一排的按钮灰色不能点. 之后查阅资料无果,最后 ...

  4. 函数lock_rec_has_expl

    判断是否预加锁的模式 要强壮于 已添加的lock锁模式 /*********************************************************************// ...

  5. 多线程操作(循环往listbox中添加数据)

    一.先造一个窗体,其中就开始按钮,暂停按钮,以及listbox文本框 二.当点击开始的时候,数据会无限的往listbox中加,为了防止卡住和提升效率,便造了一个新的线程来执行开始操作 namespac ...

  6. ArrayList集合的语句示例

    namespace ArrayList集合的语句示例{    class Program    {        static void Main(string[] args)        {    ...

  7. bzoj3668: [Noi2014]起床困难综合症

    从高位到低位枚举期望的应该是ans最高位尽量取一.如果该数最高位为o的话能够取得1直接更新ans否则判断该位取1是否会爆m不会的话就加上. #include<cstdio> #includ ...

  8. Book 最短路算法

    用HDU2544整理一下最近学的最短路算法 1.Dijkstra算法 原理:集合S表示已经找到最短路径的点,d[]表示当前各点到源点的距离 初始时,集合里面只有源点,当每个点u进入集合S时,用d[u] ...

  9. HDFS 整体把握

    对于HDFS这样一个分布式文件系统,它的目的是为了实现在多台廉价X86服务器上实现大文件存储.     HDFS 是仿造GFS 设计出来的. 如图所示, 这种实现方案是一种采取有一个中心节点, 多个数 ...

  10. pandas