2017年9月28日 星期四

如何 mirror 一個 git-project (old) 到另一個 git-project (new)

若要完整備份協同專案到自家的私人 repo 中,這招就很好用...



1. open git bash (cmder 也可以) & 在私人 repo 中建立一個新的空白專案 (new-repository/private-project)

2. 建立一個暫存的資料夾,執行下行指令
git clone --bare https://github.com/exampleuser/old-repository.git
    a. https://github.com/exampleuser/old-repository.git 可以改為 git@gitlab.com:simon01/cowork-project.git
    b. 而 old-repository.git(cowork-project.git) 就是將要被 copy 的專案名稱

3. Mirror-push to the new repository.
cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
    a. cd 進到 old-repository.git 資料夾中 (會建立一個新的資料夾叫做 old-repository.git )
  b. https://github.com/exampleuser/new-repository.git 亦可改為 git@gitlab.com:simon02/private-project.git
  c. 而 new-repository.git (private-project.git) 是要複製過來的專案
d. 做完這階段,就把 co-work 的專案 copy 到自己 private 的專案了@gitlab

4. Remove the temporary local repository you created in step 1. (就是把 old-repository.git 的資料夾砍掉)
cd ..
rm -rf old-repository.git
- 若有需要,就再從 gitlab 自己 clone private 專案下來


參考 gitHub 官方文件
https://help.github.com/articles/duplicating-a-repository/

0 意見:

張貼留言