关于gitlab/github出现“failed to push some refs to xxx”问题
1、关于问题描述
[root@bogon autobuildwebsite]# git push -u origin master
To git@IP:xxxxx.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to git@IP:xxxxx.git
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge 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@xxxxx
![拒绝]master->master(先取)
错误:未能将某些引用推送到“git@xxxxx”
提示:更新被拒绝,因为远程包含您所做的工作,本地没有。这通常是由另一个存储库推送引起的。指向同一引用。您可能希望首先合并远程更改(例如, “git pull”),然后再按有关详细信息,请参见“git push--help”中的“关于快进的说明”。
2、问题分析
此处我使用linux服务器上传文件到gitlab远程仓库,未成功。提示我使用过另一个存储库给gitlab推送过,导致更新失败,因为linux的本地代码仓库,没有远程gitlab仓库的部分文件导致。
3、解决方案
1)方案一
①使用在linux本地git工作目录,使用 git pull --rebase origin master 命令,将远程gitlab仓库更新下载到本地
②再次使用 git push -u origin master 命令上传
但是这种办法依然报了如上错误
2)方案二
①使用 git clone git@xxxxx.git 命令,将远程仓库克隆到本地
②再次提交至本地仓库:vim xxx.txt --> git add . --> git commit -m "add xxx"
③使用 git push -u origin master 命令上传至远程仓库
ok!
1、关于问题描述 [root@bogon autobuildwebsite]# git push -u origin master To git@IP:xxxxx.git ! [rejected] master -> master (fetch first) error: failed to push some refs to git@IP:xxxxx.git hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first merge 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@xxxxx ![拒绝]master->master(先取) 错误:未能将某些引用推送到“git@xxxxx” 提示:更新被拒绝,因为远程包含您所做的工作,本地没有。这通常是由另一个存储库推送引起的。指向同一引用。您可能希望首先合并远程更改(例如, “git pull”),然后再按有关详细信息,请参见“git push--help”中的“关于快进的说明”。 2、问题分析 此处我使用linux服务器上传文件到gitlab远程仓库,未成功。提示我使用过另一个存储库给gitlab推送过,导致更新失败,因为linux的本地代码仓库,没有远程gitlab仓库的部分文件导致。 3、解决方案 1)方案一 ①使用在linux本地git工作目录,使用 git pull --rebase origin master 命令,将远程gitlab仓库更新下载到本地 ②再次使用 git push -u origin master 命令上传 但是这种办法依然报了如上错误 2)方案二 ①使用 git clone git@xxxxx.git 命令,将远程仓库克隆到本地 ②再次提交至本地仓库:vim xxx.txt --> git add . --> git commit -m "add xxx" ③使用 git push -u origin master 命令上传至远程仓库 ok!