提交代码报错 error: failed to push some refs to

在本人想把本地的分支推送到远程仓库时,突然出现了错误提醒error: failed to push some refs to...。心里一咯噔,推不上去这还得了,手比脑快地就去google了一下。
然后就发现,这个error发生的情况竟然还挺多样化。鉴于自己搜到的页面,都是分散的答案,所以在此做个总结,以免日后又碰到这类错误,烂记性又促使我花费一样的时间去寻找一样的答案。

分支名不完整



emmm,这个错误大概是最难发现的了,不是说难度系数高,而是大家都把以本地master与远程master为例去写答案,于是大家会下意识忽略掉本地分支与远程分支名不一样的情况。(也可能这个大家只包含了我....)

git推送的完整写法如下:

  git push @remoteName  @localBranch:@remoteBranch

  // eg.remoteName:origin  localBranch:ceshi  remoteBranch:test
  git push origin ceshi:test

但是如果本地分支与远程分支名字一样的话,是可以简写的。例如本地和远程的分支名都是master:

 git push origin master

如果确认分支名没有错,那就继续往下看

没有提交代码



可以用 git status查看是否忘了把代码提交上去了。若是忘了,提交了就行。

  git add .
  git commit -m "This is a new commit"
  git push origin master

本地与远程产生冲突



或是有其他协作者提交了代码,或是你之前在远程上直接做了处理。这部分有两个处理方法,一是直接强覆盖,二是先把远程的变化拉取下来,解决冲突后,再一并提交。

强覆盖

  git push -f origin master
拉取再提交

  git pull –-rebase origin maste
  git push origin master

当然本人是建议能第二种就第二种,暴力美学越少见越好。

原文地址:https://www.cnblogs.com/Rivend/p/12065669.html

时间: 2024-10-10 16:00:21

提交代码报错 error: failed to push some refs to的相关文章

git push报错error: failed to push some refs to '[email protected]:

$ git push -u origin master To [email protected]:xxx/xxx.git ! [rejected] master -> master (fetch first) error: failed to push some refs to '[email protected]:xxx/xxx.git' hint: Updates were rejected because the remote contains work that you do hint:

Git push 报错 "error: failed to push some refs to " 解决

之前一直好好地啊,google后,发现是由于远程仓库中代码版本与本地不一致冲突导致的. 突然想起来,确实我在云端直接改过README,解决方法,先pull,再push,然而这时候又出现了新的问题, error: Your local changes to the following files would be overwritten by merge: Please, commit your changes or stash them before you can merge. 这时候我想用云

git连接不上远程仓库---visualstudio提交代码报错:no upstream configured for branch 'master'

1,新建文件夹,在文件下下鼠标右键git bush--->git init,初始化仓库: 2,设置gitthub仓库地址:git remote add origin https://github.com/z*****g/lm.git 3,git pull origin master 4,git push --set-upstream origin master,关联一个远程分支,并从这个分支上传下带代码 git branch查看分支 git add . git commit -m "提交注

在CentOS中安装32位或64位MySql报错error: Failed dependencies解决办法

在CentOS中安装MySql报错error: Failed dependencies解决办法 安装64位MySql报错内容如下:error: Failed dependencies:        libaio.so.1()(64bit) is needed by MySQL-server-5.6.19-1.el6.x86_64    libaio.so.1(LIBAIO_0.1)(64bit) is needed by MySQL-server-5.6.19-1.el6.x86_64    

error: failed to push some refs to ‘git@xxx.git‘

[问题描述]:通过 git push -u origin master 提交代码时出现如下报错: ##git push -u origin master Enumerating objects: 96, done. Counting objects: 100% (96/96), done. Delta compression using up to 4 threads Compressing objects: 100% (74/74), done. Writing objects: 100% (

Git error (failed to push some refs)解决

当修改了本地仓库后 提交代码时, 用 git push 提示以下错误 error:failed to push some refs to ... Dealing with "non-fast-forward" errors From time to time you may encounter this error while pushing: $ git push origin master To ../remote/ ! [rejected] master -> master

Git本地分支版本过低导致的push错误 error: failed to push some refs to ... 及后续amend

今天在用git的时候遇到了一个问题.在想远程分支push的时候,出现了下面的错误: ! [remote rejected] master -> refs/for/master (change 144 closed) error: failed to push some refs to ... 检查了一下发现是因为本地分支的版本相比远程分支的版本低. 解决的过程中有如下问题: 1.(不建议使用)直接在当前分支pull了一下,合并的时候发现有冲突,解决后commit --amend出错,大意是"

【git】error: failed to push some refs to

在使用git 对源代码进行push到gitHub时可能会出错 error: failed to push some refs to ... 出现错误的主要原因是github中的README.md文件不在本地代码目录中 可以通过如下命令进行代码合并 git pull --rebase origin master 执行上面代码后可以看到本地代码库中多了README.md文件 再执行语句 git push -u origin master即可完成代码上传到github 如何把本地项目上传到Github

github 如何解决error: failed to push some refs

错误 error: failed to push some refs to 'https://github.com/whitclass/scrapy-spider.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