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

如果输出是这样的:

* (no branch)
master

然后做

git checkout master

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

其他回答

正如错误消息所说:在你尝试git push之前,git拉。显然,您的本地分支与跟踪分支不同步。

根据项目规则和你的工作流程,你可能还想使用git pull -rebase。

我刚刚收到这个错误。

我创建了一个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回购,并在两端重新创建相同的。目前还好。

我也得到了同样的错误,但我很容易解决它通过获取其url 作为

git fetch origin Your repository origin

然后简单地应用命令

git push -f origin master

你会得到一个好结果

我也有同样的问题。 我使用Git Totoise。 右击->TotoiseGit ->清理。 现在你可以推送到Github了 这对我很有效:D