【问题标题】:non-fast-forward error in gitgit中的非快进错误
【发布时间】: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


【解决方案1】:

git remote add 之后,远程 repo 的 URL 在你的中是已知的,但还不是它的内容。

git fetch origin(或git pull)之后,您将能够git push,因为然后远程回购的内容将是已知的。

【讨论】:

  • 不。我按照你说的做了(git fetch origingit push),但我仍然遇到与上述相同的错误。出了什么问题?
猜你喜欢
  • 1970-01-01
  • 2011-12-07
  • 2014-06-25
  • 1970-01-01
  • 1970-01-01
  • 2012-07-23
  • 2015-07-22
  • 2019-06-23
  • 2016-10-20
相关资源
最近更新 更多