クラウド上など、Git リポジトリがインターネット上にある場合、大きなリポジトリを扱うときには clone するのに時間がかかるので ローカルネットワークにミラーサーバーを作ることで転送にかかる時間を節約することができます。
その際、git submodule を含むリポジトリの場合注意が必要なので具体例を踏まえながら運用を説明します
ポイントは submodule は絶対パス以外に相対パスも使えるということです。 これでピンとくる人は後は読まなくてもいいいです。
場所 | 説明 | 名前 | URL |
---|---|---|---|
GitHub | 親リポジトリ | submod-parent | https://github.com/m-tmatma/submod-parent.git |
GitHub | Submodule 1 | submod1 | https://github.com/m-tmatma/submod1.git |
GitHub | Submodule 2 | submod2 | https://github.com/m-tmatma/submod2.git |
Bitbucket | 親リポジトリ (ミラー先) | submod-parent | https://bitbucket.org/m-tmatma/submod-parent.git |
Bitbucket | Submodule 1 (ミラー先) | submod1 | https://bitbucket.org/m-tmatma/submod1.git |
Bitbucket | Submodule 2 (ミラー先) | submod2 | https://bitbucket.org/m-tmatma/submod2.git |
D:\demo>git clone https://github.com/m-tmatma/submod1.git Cloning into 'submod1'... warning: You appear to have cloned an empty repository.
D:\demo>cd submod1 D:\demo\submod1>echo test1 > test1.txt D:\demo\submod1>git add test1.txt D:\demo\submod1>git commit -m "add test1.txt" [master (root-commit) fef6a0b] add test1.txt 1 file changed, 1 insertion(+) create mode 100644 test1.txt
D:\demo\submod1>git push origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 228 bytes | 228.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/m-tmatma/submod1.git * [new branch] master -> master
D:\demo>git clone https://github.com/m-tmatma/submod2.git Cloning into 'submod2'... warning: You appear to have cloned an empty repository.
D:\demo>cd submod2 D:\demo\submod2>echo test2 > test2.txt D:\demo\submod2>git add test2.txt D:\demo\submod2>git commit -m "add test2.txt" [master (root-commit) 5bb30aa] add test2.txt 1 file changed, 1 insertion(+) create mode 100644 test2.txt
D:\demo\submod2>git push origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 226 bytes | 226.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://github.com/m-tmatma/submod2.git * [new branch] master -> master
D:\demo>git clone https://github.com/m-tmatma/submod-parent.git Cloning into 'submod-parent'... warning: You appear to have cloned an empty repository.
D:\demo>cd submod-parent D:\demo\submod-parent>echo test-parent > test-parent.txt D:\demo\submod-parent>git add test-parent.txt D:\demo\submod-parent>git commit -m "add test-parent.txt" [master (root-commit) 3728826] add test-parent.txt 1 file changed, 1 insertion(+) create mode 100644 test-parent.txt
D:\demo\submod-parent>git submodule add ../submod1 submod1 Cloning into 'D:/demo/submod-parent/submod1'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. warning: LF will be replaced by CRLF in .gitmodules. The file will have its original line endings in your working directory D:\demo\submod-parent>git submodule add ../submod2 submod2 Cloning into 'D:/demo/submod-parent/submod2'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. warning: LF will be replaced by CRLF in .gitmodules. The file will have its original line endings in your working directory
D:\demo\submod-parent>git status On branch master Your branch is based on 'origin/master', but the upstream is gone. (use "git branch --unset-upstream" to fixup) Changes to be committed: (use "git reset HEAD..." to unstage) new file: .gitmodules new file: submod1 new file: submod2
D:\demo\submod-parent>git commit -m "add submodule" [master e60d89e] add submodule 3 files changed, 8 insertions(+) create mode 100644 .gitmodules create mode 160000 submod1 create mode 160000 submod2
D:\demo\submod-parent>git push origin master Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 16 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 614 bytes | 614.00 KiB/s, done. Total 6 (delta 0), reused 0 (delta 0) To https://github.com/m-tmatma/submod-parent.git * [new branch] master -> master
D:\demo\submod1>git remote -v origin https://github.com/m-tmatma/submod1.git (fetch) origin https://github.com/m-tmatma/submod1.git (push) D:\demo\submod1>git remote add mirror https://bitbucket.org/m-tmatma/submod1.git
D:\demo\submod1>git remote -v mirror https://bitbucket.org/m-tmatma/submod1.git (fetch) mirror https://bitbucket.org/m-tmatma/submod1.git (push) origin https://github.com/m-tmatma/submod1.git (fetch) origin https://github.com/m-tmatma/submod1.git (push)
D:\demo\submod1>git push mirror master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 228 bytes | 228.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://bitbucket.org/m-tmatma/submod1.git * [new branch] master -> master
D:\demo\submod2>git remote -v origin https://github.com/m-tmatma/submod2.git (fetch) origin https://github.com/m-tmatma/submod2.git (push) D:\demo\submod2>git remote add mirror https://bitbucket.org/m-tmatma/submod2.git
D:\demo\submod2>git remote -v mirror https://bitbucket.org/m-tmatma/submod2.git (fetch) mirror https://bitbucket.org/m-tmatma/submod2.git (push) origin https://github.com/m-tmatma/submod2.git (fetch) origin https://github.com/m-tmatma/submod2.git (push)
D:\demo\submod2>git push mirror master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 226 bytes | 226.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://bitbucket.org/m-tmatma/submod2.git * [new branch] master -> master
D:\demo\submod-parent>git remote -v origin https://github.com/m-tmatma/submod-parent.git (fetch) origin https://github.com/m-tmatma/submod-parent.git (push) D:\demo\submod-parent>git remote add mirror https://bitbucket.org/m-tmatma/submod-parent.git
D:\demo\submod-parent>git remote -v mirror https://bitbucket.org/m-tmatma/submod-parent.git (fetch) mirror https://bitbucket.org/m-tmatma/submod-parent.git (push) origin https://github.com/m-tmatma/submod-parent.git (fetch) origin https://github.com/m-tmatma/submod-parent.git (push)
D:\demo\submod-parent>git push mirror master Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 16 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 614 bytes | 614.00 KiB/s, done. Total 6 (delta 0), reused 0 (delta 0) To https://bitbucket.org/m-tmatma/submod-parent.git * [new branch] master -> master
D:\demo>git clone https://bitbucket.org/m-tmatma/submod-parent.git mirror Cloning into 'mirror'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (6/6), done.
D:\demo>cd mirror D:\demo\mirror>git remote -v origin https://bitbucket.org/m-tmatma/submod-parent.git (fetch) origin https://bitbucket.org/m-tmatma/submod-parent.git (push) D:\demo\mirror>git submodule init Submodule 'submod1' (https://bitbucket.org/m-tmatma/submod1) registered for path 'submod1' Submodule 'submod2' (https://bitbucket.org/m-tmatma/submod2) registered for path 'submod2' D:\demo\mirror>git submodule update Cloning into 'D:/demo/mirror/submod1'... Cloning into 'D:/demo/mirror/submod2'... Submodule path 'submod1': checked out 'fef6a0b0567400d56de933c6124de6c7a3fb2edb' Submodule path 'submod2': checked out '5bb30aae61a7a2b729639ed0b16167adafb9cd37'