山里狼

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

  如果git push出现下面错误

“To git@github.com:username/username.github.com.git ! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘git@github.com:username/username.github.com.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 push -f

-f 强制执行

2.先把git仓库的代码fetch下来,merge后然后在push

$ git fetch

$git merge

其实,这两句可以简写成一句

$git pull

如果出现下面without telling which branch时,你应该配置一下

上面出现的 [branch "master"]是需要明确(.git/config)如下的内容
[branch "master"]
    remote = origin

    merge = refs/heads/master

这等于告诉git2件事:

1,当你处于master branch, 默认的remote就是origin。

2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上所有的改变

如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:

$ git config branch.master.remote origin

$ git config branch.master.merge regs/heads/master

之后重新push一下就行了

 

posted on 2013-08-20 09:31  山里狼  阅读(545)  评论(0编辑  收藏  举报