在github创建一个仓库后,会自动生成一个README.md文件,但是在本地的仓库中并没有该文件,因此需要将该文件从github仓库中pull下来,如果没有pull下来,当你将本地项目push到github中的仓库中,就会出现如图所示的错误:
non-fast-forward问题的出现在于:git仓库中已经存在一部分代码,它不允许你直接把你的代码覆盖上去。于是,有两种选择方式:
1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容。
git push -f
2,先把git的东西fetch到本地,然后merge,后在push
git fetch
git merge
这两句等价于git pull
使用git pull命令后,又出现如下的问题:
1,当你处于master branch,默认的remote就是origin。
2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上的所有的改变。
如果不想或者不会编辑config文件的话,可以在git bash上输入以下命令:
-
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
之后再重新git pull下,最后git push代码,就行了。
参考:http://www.linuxidc.com/Linux/2012-04/58985.htm