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

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

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

其他回答

我已经在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>

希望能有所帮助。

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

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

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

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

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

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

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

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

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

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

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

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

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