当我试图将我的代码推送到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,一切都会同步,错误就会消失。

`

其他回答

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

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

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

有时我们忘记了牵引,在当地环境中做了很多工作。

如果有人想只推不拉,

git push --force

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

我已经在GIT存储库中解决了这个问题。在这种情况下,不需要重新设置或强制提交。使用以下步骤解决此问题-

local_barnch> git branch --set-upstream to=origin/<local_branch_name> 

local_barnch>git pull origin <local_branch_name>

local_barnch> git branch --set-upstream to=origin/master

local_barnch>git push origin <local_branch_name>

希望能有所帮助。

推送前是否更新了代码?

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

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

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

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

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

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

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