Try   HackMD

將本地 Repository 同時 push 到多個 Remote Repository 上

操作說明

假設 remote repository 如下:

git@my_repo_host1/my_repo.git
git@my_repo_host2/my_repo.git
  1. 進入本地 repository,確認目前的 remote repository

    ​$ cd my_repo
    ​$ git remote -v
    

    執行結果如下:

    ​origin git@my_repo_host/my_repo.git (fetch)
    ​origin git@my_repo_host/my_repo.git (push)
    
  2. 設定新的 remote repository
    注意:第一個設定會覆蓋原本的設定

    ​$ git remote set-url --add --push origin git@my_repo_host1/my_repo.git
    ​$ git remote set-url --add --push origin git@my_repo_host2/my_repo.git
    ​$ git remote -v
    

    執行結果如下:

    ​origin git@my_repo_host/my_repo.git (fetch)
    ​origin git@my_repo_host1/my_repo.git (push)
    ​origin git@my_repo_host2/my_repo.git (push)
    
  3. 設定完成後,只需要輸入 git push 即可同時將本地 repository push 至多個 remote repository
    如果需要修改設定,可使用 git config -e 開啟預設編輯器修改


參考資料

How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.