專案同步兩個git倉庫,如同時傳到gitee和github
阿新 • • 發佈:2019-08-12
有時候我們為了保證倉庫程式碼安全,可能將git程式碼傳送到兩個不同的git程式碼倉庫。接下來演示下如何進行操作:
- 首先創立兩個倉庫
#假定建立好的兩個倉庫地址分別為: https://gitee.com/cigoos/mycode.git https://github.com/cigoos/mycode.git
- 先從其中一個倉庫檢出程式碼
git clone https://gitee.com/cigoos/mycode.git
- 刪除倉庫origin
git remote rm origin
- 關聯兩個遠端倉庫
# 關聯gitee git remote add gitee https://gitee.com/cigoos/mycode.git git push gitee master # 關聯github git remote add github https://github.com/cigoos/mycode.git git push github master
# 注意此時如果遇到下述問題 To https://github.com/CigoOS/cigoadmin_tp5.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/cigoos/mycode.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 integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. # 此時要先執行 git pull github master --allow-unrelated-histories