GIT第二次推送失败

GIT第二次推送失败,git,github,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:uniqueda

我是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 push之前,我尝试了git pull

但我还是犯了同样的错误

我在堆栈上看到了许多类似的问题,但没有多少帮助。非常感谢您的帮助

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

或者我可以做一个
git拉
,然后添加我的文件,然后做一个


提前谢谢

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

更新被拒绝,因为当前分支的提示已过期

如果我们的分支机构没有更新服务器,Git将不允许您推送更改

尝试
将代码推送到远程repo-git后,请验证“本地”分支是否拥有来自远程分支的所有最新代码。如果它发现您缺少一些提交,它将不允许您将代码推送到远程


如何修复它? 它非常简单-您只需通过以下方式之一从服务器中提取更改:

# 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>
#假设您在所需的分支上
#使用服务器上的所有最新代码更新本地服务器
#这是一个可选命令,但始终使用它是一个很好的实践
#与服务器同步
git fetch--全部--prune
#现在将(pull=fetch+merge)更改从服务器拉到分支
git拉原点
#现在您的本地分支是最新的,并且包含所有“服务器”代码
#将更改推送到远程分支
git推送原点

你确定你已经拉了吗?这就是错误消息希望您执行的操作。如果
git pull
first不能执行此操作,您可以运行
git status
并在此处显示输出吗?
git fetch
是多余的,如果您使用
git pull
,它自己执行提取。由于您刚刚获取,下一个命令应该是
git merge origin/
(或
git rebase origin/
),而不是
git pull origin
。同意我在回答中提到的