当我试图将我的代码推送到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拉https://github.com/username/repository 这是因为Github和远程存储库不同步。如果你拉了repo,然后Push,一切都会同步,错误就会消失。

`

其他回答

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

在我当地的'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专家,但是我被可靠地告知这个工作流可能会避免我遇到的特定问题。

造成这个问题的另一个原因(显然不太常见)是……

当我进行推送时,我的服务器延迟了大约12个小时

我在服务器上配置了NTP同步我的时钟。

我执行了一个新的git推送,导致了这篇文章中讨论的错误。

推送前是否更新了代码?

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

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

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

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

`

我在我的教程《如何使用GitHub:初学者教程》中提到了这一点。

当你在GitHub上创建一个新的存储库时,GitHub可能会要求你创建一个自述文件。如果你直接在GitHub上创建自述文件,那么你需要首先在“推送”请求成功之前发出“拉”请求。 这些命令将“拉”远程存储库,将其与当前文件合并,然后将所有文件“推”回GitHub:

git pull https://github.com/thomas07vt/MyFirstRepo.git master

git push https://github.com/thomas07vt/MyFirstRepo.git master