当我试图将我的代码推送到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检查您的本地分支是否过期,并在需要时进行拉取也是值得的

其他回答

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

在我当地的'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 push --force

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

当我试图推我当前的分支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进行清理

当我将最新的更改推到我用于gitweb的裸Git存储库时,我得到了类似的错误。在我的例子中,我没有在裸库中做任何更改,所以我只是删除了我的裸库并再次克隆:

git clone --bare <source repo path> <target bare repo path>

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