GitHub--git push出错解决
当使用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出错解决的更多相关文章
- [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 ...
- git push出错的解决办法
今天push代码到线上的时候怎么都不行,尝试了很多办法报了好几种错比如: 反正就是各种错,然后其实不管什么错,你全部Git init 一下然后重新配置 git config --global user ...
- Linux] Git: push 出错的解决 master -> master (branch is currently checked out)
在使用Git Push代码到数据仓库时,提示如下错误: [remote rejected] master -> master (branch is currently checked out ...
- git push冲突解决
1. 首先,可以试图用git push origin branch-name推送自己的修改:2. 如果推送失败,则因为远程分支比你的本地更新,需要先用git pull试图合并:如果git pull提示 ...
- 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 ...
- [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/ ...
- git命令行解决冲突文件步骤
原文https://blog.csdn.net/zwl18210851801/article/details/79106448 亲测有用,解决git冲突的好办法 方法一(推荐使用): git pull ...
- 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 ...
- (诊断)解决GitHub使用双因子身份认证“Two-Factor Athentication”后无法git push 代码的“fatal: Authentication failed for ...”错误
在GitHub上采取双因子身份认证后,在git push 的时候将会要求填写用户的用户名和密码,用户名就是用户在GitHub上申请的用户名,但是密码不是普通登录GitHub的密码. 一旦采取双因子身份 ...
随机推荐
- PHP empty函数判断0返回真还是假?
最近项目中,遇到一个字段是 “是否启用”值为0,1 在查询时没想就写了 if ( isset($args_array['useFlg']) && !empty($args_array[ ...
- VennDiagram 画文氏图/维恩图/Venn
install.packages("VennDiagram")library(VennDiagram) A = 1:150B = c(121:170,300:320)C = c(2 ...
- gridview 单击行时如何让SelectedIndexChanging事件响应
在gridview控件上单击行的时候,是不触发SelectedIndexChanging事件的,那么想要单击时触发SelectedIndexChanging事件时怎么做呢? 我是这样做的: 在grid ...
- URAL1355. Bald Spot Revisited
1355 其实就是求质因子的个数 这样肯定是最多的 注意一下 除到最后不是1的情况 #include <iostream> #include<cstdio> #include& ...
- 浅谈Websocket、Ajax轮询和长连接(long pull)
最近看到了一些介绍Websocket的文章,觉得挺有用,所以在这里将自己的对其三者的理解记录一下. 1.什么是Websocket Websocket是HTML5中提出的新的协议,注意,这里是协议,可以 ...
- Bootstrap_组件
一.Glyphicons 字体图标 1.所有可用的图标查看:http://v3.bootcss.com/components/ 2.获取字体图标:我们已经在 环境安装 章节下载了 Bootstrap ...
- 随便谈谈alphago与人机大战
3月16日历时8天的人机大战终于落下帷幕,alphago以4:1的比分击败了当年如日中天的李世石.这个结果让我这个围棋爱好者+计算机爱好者百感交集…… ——一个时代落幕了,一个新的时代开启了. 这次人 ...
- 使用mysql索引的规则
注意事项: 1)索引并不是越多越好 创建索引是会占用非常多的硬盘空间的,一般来说,一张表的索引的大小是其数据大小的2到3倍: 所以不要随便创建无用的索引,一般来说,只要给学用来做条件(where.or ...
- BZOJ 1202 狡猾的商人
前缀和+带权并查集. #include<iostream> #include<cstdio> #include<cstring> #include<algor ...
- TCP握手
1.TCP的三次握手四次挥手 第一次握手:Client将标志位SYN置为1,随机产生一个值seq=J,并将该数据包发送给Server,Client进入SYN_SENT状态,等待Server确认. 第二 ...