`
xfxlch
  • 浏览: 162616 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

how to fix: error: failed to push some refs to

    博客分类:
  • GIT
阅读更多
最近在看GIT的相关教程,是廖雪峰老师的教程:http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
这个教程是从入门开始的,所以也还比较好懂。教程的前半部分都是在本地的操作,一切都是没有什么问题的,但是当要把本地的代码push到远程仓库的时候,就遇到了一个小的问题。因为我是在github上建立了一个learngit的仓库,并且建立的时候,顺便勾选建立readme.md文件,作为仓库的第一个提交。
下面是我的执行过程。
$git remote add origin git@github.com:xfxlch/learngit.git //添加远程主机名
$git push -u origin master //把本地的master分支代码push到远程仓库的master分支上。
这个时候得到了下面的错误。
引用

To git@github.com:xfxlch/learngit.git
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:xfxlch/learngit.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


然后我就用去执行了如下的命令:
$git pull origin master
执行完之后,什么都提示都没有,然后我再想去push代码的时候,仍然出现了之前的错误。

我很沮丧,就去Google了,然后找到了http://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to

引用

git pull --rebase origin master
git push origin master


完整的是这样的
引用

luchenghaodeMacBook-Air:learngit luchenghao$ git pull --rebase origin master
From github.com:xfxlch/learngit
* branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: add readme
Applying: udpated
Applying: small change
Applying: understand how stage  works
Applying: check git status
Applying: add test.txt
luchenghaodeMacBook-Air:learngit luchenghao$ git push origin master
Counting objects: 18, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (18/18), 1.48 KiB | 0 bytes/s, done.
Total 18 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), done.
To git@github.com:xfxlch/learngit.git
   4587b43..a5dca30  master -> master



他会replay之前的操作,就是相当于把我在本地的commit和在github上的commit做一次 彩排,到底哪个先哪个后,按时间顺序排一下,然后再push的时候,就可以正常提交了。

--EOF--

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics