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

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


当前回答

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

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

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

其他回答

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

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

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

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

git checkout test

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

git checkout -b testing

现在,是时候推它了:

git push [remote repo] testing

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

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

git pull origin branch_name --rebase

这对我来说是可行的——命令git pull origin branch_name——rebase将首先从远程branch_name中提取更改,然后在其顶部重新设置当前分支。

使用git拉https://github.com/username/repository 这是因为Github和远程存储库不同步。如果你拉了repo,然后Push,一切都会同步,错误就会消失。

`

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

场景,

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