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的密码. 一旦采取双因子身份 ...
随机推荐
- dd命令刻录u盘启动盘
dd命令来刻录windows启动盘 dd if=/ home/avi/Downloads/Win10_English_x64.iso of=/ dev/sdb1 bs=51M; sync dd命令详解 ...
- dojo 七 DOM dojo/dom
官方教程:Dojo DOM Functions对dom的使用,需要引用包dojo/dom.1.获取节点,dom.byIdbyId中既可以传递一个字符串,也可以传递一个节点对象 require([&qu ...
- 利用SOLR搭建企业搜索平台 之——solr的查询语法
1. 首先假设我的数据里fields有:name, tel, address 预设的搜寻是name这个字段, 如果要搜寻的数据刚好就是 name 这个字段,就不需要指定搜寻字段名称. 2. 查询规 ...
- 第四篇 在中国做ERP系统实施你必须知道的一些常识
1. ERP实施要特别从参与全球竞争的视角指引系统建设.中国社会经历了一个从计划经济体制到市场经济体制的转变.中国加入WTO后,要与国际接轨,要按照世界贸易组织有关的贸易规则开展国际贸易.中国的关税与 ...
- leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)
一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...
- Eclipse引用Library失败的问题
整个导入流程严格按照guide的内容操作,但是始终无法导入,设置导入后项目中不出现相关的Library project.在设置完library之后重新打开始始终显示关联错误,就是reference那里 ...
- tc srm 632 500 (规律)
We have a sequence of N positive integers: a[0] through a[N-1]. You do not know these integers. All ...
- core--多线程
WINDOWS是一个多线程操作系统,所谓多线程,就是在同一时间里,有多个线程同时在运行.我们上一遍说到CPU的执行序列是严格按照顺序来执行,怎么能够同一时间来执行很多程序呢?在早期答案是:window ...
- Qt环境搭建(Visual Studio)
简述 经常有人问我编写Qt程序时使用什么IDE,其实这个真的很难回答(各有所长),只能说看个人爱好了,因为我两个都用,而且两个都很喜欢(比较多情吧O(∩_∩)O~)! 下面将进行Qt Creator与 ...
- 【第二篇】.NET用NPOI读取Excel表格并在页面预览
博主用的是npoi2.0.1,支持.xls也支持.xlsx 直接上代码吧. <table class="table table-bordered table-striped" ...