Try   HackMD

搬移 Remote Repository 到另一個 Remote Repository

前言

當原本的 remote repository 位於私人網域,GitHub 或 Bitbucket 可能無法透過 http 或 ssh 複製 remote repository,此時可以採用以下做法:先將 repository 拉至本地端,再重新 push 新的 repository 上。

操作說明

  1. clone remote repository

    ​git clone ssh://git@my_repo_host/my_repo.git
    
  2. 進入資料庫,將所有 remote branch 拉下來

    cd my_repo
    ​for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; 
    ​	do git branch --track ${branch#remotes/origin/} $branch;
    ​done
    
  3. 刪除原本的 origin

    ​git remote rm origin
    ​git remote -v # Check
    
  4. 新增新的 origin

    ​git remote add origin ssh://my_new_repo_host/my_repo.git
    ​git remote -v # Check
    
  5. 將本地 repository 推上新的 repository

    ​git push -u --all origin
    

參考資料