【发布时间】:2013-01-09 11:15:12
【问题描述】:
我想在我现有的项目中使用 git,所以我在 github 上为它创建了一个空间,并在我主机上的项目文件夹中我做了通常的操作:
$ git config --global user.name myname
$ git config --global user.email "myemail@email.com"
$ cd myProjectFolder/
$ git init
$ git add .
$ git commit -m "first commit"
$ git remote add origin https://github.com/myusername/myprojectname.git
然后我希望我的项目的所有文件也在在线存储库中:
$ git push origin master
但我得到了以下可怕的错误:
To https://github.com/myusername/myprojectname.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/myusername/myprojectname.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.
现在,我无需从在线存储库中pull,因为那里仍然没有任何内容。为什么要拉?
无论如何,我应该在这里做什么才能让我的所有文件在线并开始使用 git?
【问题讨论】:
-
做一个
git fetch --all:当你创建你的github repo时,你有没有告诉它添加一个自述文件之类的? -
...如果您这样做了,则意味着您的 GitHub 存储库中有尚未在本地存储库中的提交。按照错误提示运行
git pull将使您的本地存储库保持最新,此时您可以push。
标签: git version-control github git-pull