GIT 2nd PUSH失败了

时间:2016-02-17 20:31:54

标签: git github

我是git的新手。

我正在尝试使用git push origin master将我的新代码推送到远程存储库。但它失败了以下错误:

To git@gitlab.unique.com:uniquedata-analytics/TEST-SAS.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@gitlab.unique.com:uniquedata-analytics/TEST-SAS.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

我在git pull之前尝试了git push

我仍然得到同样的错误。

我在堆栈上看到了很多类似的问题,但没有多大帮助。任何帮助都非常感谢。

我是否需要执行任何远程克隆,然后添加我的文件,然后执行push

或者我可以执行git pull,然后添加我的文件然后执行push

提前致谢。

2 个答案:

答案 0 :(得分:1)

  

Updates were rejected because the tip of your current branch is behind

如果我们的分支机构与服务器不是最新的,那么Git将不允许您推送更改

尝试将push代码发送到远程repo git后,请验证您的" local" branch具有来自远程分支的所有最新代码。如果它发现你缺少某些提交,它将不允许你将代码推送到遥控器。

如何解决?

非常简单 - 您只需要通过以下方式之一从服务器提取更改:

# assuming you are on the desired branch

# update your local server with all the latest code from the server
# This is an optional command but its a good practice to always be 
# synchronized with the server
git fetch --all --prune

# now pull (pull = fetch + merge) the changes from the server to your branch
git pull origin <branch name>

# now your local branch is up to date and contains all the "server" code as well

# push your changes to the remote branch
git push origin <branch name>

答案 1 :(得分:0)

您必须执行另一个 git pull ,因为您当地的当前分支位于远程分支之后。即使您已经执行了 git pull ,也不会阻止其他人在您的下一次 git push 之前执行他们自己的 git push 。这是一个常见的git场景。