Git

git出现error: failed to push some refs to ‘https://gitee.com/test.git’ hint: Updates were rejected because the tip of your current branch is behind

rzk · 8月28日 · 2020年本文共814个字 · 预计阅读3分钟95次已读

问题

$ git push origin mast睿共享er
To https://gitee.com/test.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/test.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote ch睿共享a睿共享nges (e.g.
hint:睿共享 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

问题所在及其解决办法

本地创建了一个Test文件夹

并在码云上创建了一个Test仓库,想要将本地的仓库链接到远程仓库

用的是如下方法:

git init    初始化本地仓库
git remote add origin XXX     添加远程仓库地址

如果你在这之后就执行

git add -A,
git commit -m " "
git睿共享 push origin master,那么就会出现这个问题(被拒绝),所以在remote add后不要着急git add,一定要git pull origin master,出现这个原因
是因为你在码云创建的仓库有ReadMe文件,而本地没有,造成本地和远程的不同步

那么有两种方案可以解决:

one :

本地没有ReadMe文件,那么就在本地生成一个:

git pull --rebase origin master     本地生成ReadMe文件
git push origin master

two:

那我就强制上传覆盖远程文件,

git push -f origin master
(这个命令在团队开发的时候最好不要用,否则可能会有生命危险)
0 条回应