我试图推动我的项目(所有文件在一个新的存储库)。我遵循这些步骤,但当我用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.

我得到这个错误很多次,不知道该怎么做。


当前回答

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

其他回答

试试这个命令:"git pull origin master"

这对我很管用。

查看这个链接:https://help.github.com/articles/dealing-with-non-fast-forward-errors

! master -> master(非快进)

不要惊慌,这很容易解决。你所要做的就是发出一个拉,你的分支就会快进:

$ git pull myrepo master

然后重试你的推送,一切都会好起来的:

$ git推github master

我刚刚收到这个错误。

我创建了一个github存储库后,创建我的本地git存储库,所以我需要在推送到github之前接受到本地的更改。在这种情况下,唯一的变化是创建github存储库时作为可选步骤创建的自述文件。

git pull https://github.com/*username*/*repository*.git master

存储库URL从这里得到的项目github页面:

然后重新初始化(这可能不需要)

git init
git add .
git commit -m "update"

然后按:

git push

这意味着您的远程git存储库配置为denynonfastforward = true。虽然很危险,但有时你可能真的需要覆盖git的历史记录(例如,在运行bfg——strip-blobs-big -than 100M之后),因此你可以临时将该设置修改为false (denynonfastforward = true,在your-repository.git/config中看到它),然后强制push(即git push -f)。

你需要做的

git branch

如果输出是这样的:

* (no branch)
master

然后做

git checkout master

确保没有任何挂起的提交,因为签出会丢失所有未提交的更改。