当我试图将我的代码推送到GitHub时,我遇到了一些问题。

Pushing to git@github.com:519ebayproject/519ebayproject.git
To git@github.com:519ebayproject/519ebayproject.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:519ebayproject/519ebayproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我还没有在存储库中推入任何东西,那么为什么我需要拉出一些东西呢?


当前回答

我也遇到过类似的问题,结果是我保持分支保持最新的工作流程出了问题。我正在做以下事情:

在我当地的'master'中

git fetch upstream
git merge upstream/master --ff-only

然后回到我当地的分行

git rebase master

这适用于以前的git流,但不适用于github。git rebase是导致同步问题的问题(我承认这是我不得不接受的,但没有完全理解),不幸的是,git push -f可能是最简单的选择。不好的。

我的新流程是直接使用git merge来更新分支,如下所示:

在我当地的分行

git fetch upstream
git merge upstream/master

没有快进,因为我将在本地分支中做出改变。

正如你可能知道的那样,我不是git专家,但是我被可靠地告知这个工作流可能会避免我遇到的特定问题。

其他回答

有些人可能会遇到这个错误,因为Git不知道您要推哪个分支。

如果您的错误消息还包括

error: failed to push some refs to 'git@github.com:jkubicek/my_proj.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration
hint: variable to 'current' or 'upstream' to push only the current branch.

那么你可能想要遵循Jim Kubicek的提示,将Git配置为只推送当前分支,将默认分支设置为当前分支。

git config --global push.default current

如果git pull print Already - up- up,那么你可能想检查全局git push.default参数(In ~/.gitconfig)。如果匹配,则将其设置为simple。下面的答案解释了原因:

Git: push.default "matching"和"simple"有什么区别?

此外,使用git remote show origin检查您的本地分支是否过期,并在需要时进行拉取也是值得的

在我的情况下,我检查了“mybranch”,并做了git pull,所以我不知道为什么推不起作用。最后,我意识到我推错了树枝。我输入的是git push origin master而不是git push origin mybranch。

如果你已经做了git pull,仍然收到这个消息,确保你推的是正确的分支。

除了上面的答案,下面的答案对我很有用:-

场景,

我成功地将my_branch推到origin。 我又做了一些改动。 当我尝试再次推,(在做了添加,当然提交),我得到了上面提到的错误。

解决方案-

 1. git checkout **my_branch**
 2. git add, commit your changes.
 3. git pull origin **my_branch** (not origin, master, or develop)
 4. git push origin **my_branch**

此问题通常是由创建自述文件引起的。Md文件,被算作一个提交,在系统上不是本地同步的,并且缺少后面的头,因此,它显示一个git拉请求。您可以尝试避免自述文件,然后尝试提交。这对我来说是有效的。