我试图推动我的项目(所有文件在一个新的存储库)。我遵循这些步骤,但当我用git push -u origin master推时,我得到这个错误:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:asantoya/projectnewbies.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 Totoise。 右击->TotoiseGit ->清理。 现在你可以推送到Github了 这对我很有效:D

这也可能是由于在给Repo命名时引起的一些名称错误造成的。 如果上面的任何一个答案都不起作用,下面这个对我来说是有效的:

删除该repo并创建一个新的repo,并再次尝试以下命令:

cd 'Local Directory Path'
git remote add origin *your_git_name.git*
git push -u origin master

如果add origin显示已经存在,则使用以下方法:

git remote set-url origin *your_git_name.git*

当我在开发分支和我的主分支没有最新更新时,这种情况发生在我身上。

所以当我试图从开发分支推git时,我遇到了这个错误。

我通过切换到主分支,git拉,然后回去开发分支和git推来修复它。

$ git fetch && git checkout master
$ git pull
$ git fetch && git checkout develop
$ git push

我唯一能够解决这个问题的是删除本地和git回购,并在两端重新创建相同的。目前还好。

如果有人在尝试推到heroku时出现此错误,则只需将“origin”替换为“heroku” 是这样的: Git push -f heroku master