当我试图将我的代码推送到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.

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


当前回答

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

场景,

我成功地将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**

其他回答

使用push命令的问题是本地和远程存储库不匹配。如果你在从git hub创建新的存储库时默认初始化了自述库,那么主分支会自动创建。然而,当你试图推动,没有任何分支。你不能推…因此,最好的做法是创建没有默认自述me初始化的repo。

我遇到了同样的问题,结果是我在一个不同的(本地)分支上,而不是我认为的,正确的本地分支在远程提交时落后了。

我的解决方案:签出正确的分支,从其他本地分支中选择提交,git拉和git推

推送前是否更新了代码?

在你推送任何东西之前使用git pull origin master。

我假设您正在使用origin作为遥控器的名称。

你需要先拉后推,在你推送一些东西之前让你的本地存储库更新(以防其他人已经在github.com上更新了代码)。这有助于在局部解决冲突。

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

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

您的分支名称是否与远程分支名称相同?

如果没有,您应该签出一个与远程分支同名的新分支,并尝试再次推送它。

假设要推送的远程分支是[testing],本地分支名为[test]。

如果你不在测试分支,首先切换到它。

git checkout test

然后打开一个新的分支并命名为testing。

git checkout -b testing

现在,是时候推它了:

git push [remote repo] testing