我试图推动我的项目(所有文件在一个新的存储库)。我遵循这些步骤,但当我用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 push之前,git拉。显然,您的本地分支与跟踪分支不同步。

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

其他回答

这是因为你在master中做了一些更改,所以项目要求你先拉。如果你想推它,你可以输入以下命令使用蛮力:

git push -f origin master

记得先提交你的修改:

git add .
git commit -m "Your commit message"

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

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

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

git fetch origin Your repository origin

然后简单地应用命令

git push -f origin master

你会得到一个好结果

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

这对我很管用。

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

我在github创建了新的回购,我有同样的问题,但它也有问题,而拉,所以这为我工作。

但在已经有很多这样的代码的回购中,不建议这样做 会把一切都搞砸

git push origin master --force