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

是有效的。当你和其他人一起工作时,不建议这样做,但当你的工作是一件简单的事情或一个私人玩具项目时,这将是一个快速的解决方案。

其他回答

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

当我试图推我当前的分支foobar时,我得到了上面提到的错误消息:

git checkout foobar
git push origin foo

结果是我有两个本地分支跟踪同一个远程分支:

foo -> origin/foo (some old branch)
foobar -> origin/foo (my current working branch)

它为我工作,通过使用我的当前分支:

git push origin foobar:foo

... 并使用git分支-d进行清理

只是有同样的问题,但在我的情况下,我在遥控器上输入了错误的分支。所以,这似乎是这个问题的另一个来源……仔细检查你是否推到了正确的分支。

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

`

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

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

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

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

git checkout test

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

git checkout -b testing

现在,是时候推它了:

git push [remote repo] testing