關於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!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM