git項目初次push提示error: failed to push some refs to https://gitee.com/xxxx/gittest.git’解決方案 --九五小龐


在本地與遠程新建倉庫並關聯后,初次push可能會遇到以下問題

  1. $ git push -u origin master
  2. To https://gitee.com/xxxx/gittest.git
  3. ! [rejected] master -> master (fetch first)
  4. error: failed to push some refs to 'https://gitee.com/xxxx/gittest.git'
  5. hint: Updates were rejected because the remote contains work that you do
  6. hint: not have locally. This is usually caused by another repository pushing
  7. hint: to the same ref. You may want to first integrate the remote changes
  8. hint: (e.g., 'git pull ...') before pushing again.
  9. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因是因為遠程倉庫有一些文件而本地沒有,通常是在遠程建立倉庫時有一些初始化文件比如Readme License 等,並且直接pull會提示warning: no common commits,對於此類問題可以采用兩種解決辦法

1.git push -f 強制將本地文件推送至遠程,這樣會將遠程倉庫的已有的文件清掉

2. git pull origin master –allow-unrelated-histories 使用此命令告訴 git 允許不相關歷史合並 這樣就能把遠程文件拉取回來。執行此命令后會有一個提示,要求說明為何要講兩個不相關的分支合並,輸入信息后保存即可。

拉取完不同的文件之后再執行git push -u origin master命令即可push成功。

建議使用第二種辦法

  1. Merge branch 'master' of https://gitee.com/xxxx/gittest.git
  2. # Please enter a commit message to explain why this merge is necessary,
  3. # especially if it merges an updated upstream into a topic branch.
  4. #
  5. # Lines starting with '#' will be ignored, and an empty message aborts
  6. # the commit.
  7. Merge made by the 'recursive' strategy.
  8. .gitignore | 66 ++++++++++++
  9. LICENSE | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  10. README.en.md | 36 +++++++
  11. README.md | 37 +++++++
  12. 4 files changed, 478 insertions(+)
  13. create mode 100644 .gitignore
  14. create mode 100644 LICENSE
  15. create mode 100644 README.en.md
  16. create mode 100644 README.md


免責聲明!

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



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