Git のサブモジュールを使用してリモートリポジトリのクローンを作成する

Kevin Amayi 2024年2月15日 Git Git Clone
  1. Git のサブモジュールを使用してリモートリポジトリのクローンを作成する
  2. サブモジュールを作成し、Git でクローンを作成する前にリモートリポジトリにプッシュする
Git のサブモジュールを使用してリモートリポジトリのクローンを作成する

この記事では、サブモジュールを使用してリモート Git リポジトリのクローンを作成する方法について説明します。また、サブモジュールを作成し、クローンを作成する前にリモートリポジトリにプッシュします。

Git のサブモジュールを使用してリモートリポジトリのクローンを作成する

次のコマンドを使用して、リポジトリをサブモジュールと一緒に複製します。

git clone --recurse-submodules -j8 git@github.com:KEVINAMAYI/AkanNameGenerator.git 

出力:

Cloning into 'AkanNameGenerator'... remote: Enumerating objects: 108, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (11/11), done. remote: Total 108 (delta 4), reused 3 (delta 1), pack-reused 94 Receiving objects: 100% (108/108), 2.38 MiB | 1.86 MiB/s, done. Resolving deltas: 100% (29/29), done. Submodule 'testfolder' (git@github.com:KEVINAMAYI/AkanNameGenerator.git) registered for path 'testfolder' Cloning into '/home/kevin/tqt/AkanNameGenerator/testfolder'... remote: Enumerating objects: 108, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (11/11), done. remote: Total 108 (delta 4), reused 3 (delta 1), pack-reused 94 Receiving objects: 100% (108/108), 2.38 MiB | 1.55 MiB/s, done. Resolving deltas: 100% (29/29), done. Submodule path 'testfolder': checked out '3300a2aa47ef2c490c19541c6907117511eabe08' 

サブモジュールを作成し、Git でクローンを作成する前にリモートリポジトリにプッシュする

リポジトリのクローンを作成する前に、まず testfolder という名前のサブモジュールを既存のローカルリポジトリに追加してから、変更をリモートリポジトリにプッシュします。

<!-- this commands intializes a submodule with the contents of a remote repo--> git submodule add <your remote repo url> <name of submodule>  git submodule add git@github.com:KEVINAMAYI/AkanNameGenerator.git testfolder 

出力:

Cloning into '/home/kevin/tst/AkanNameGenerator/testfolder'... remote: Enumerating objects: 105, done. remote: Counting objects: 100% (11/11), done. remote: Compressing objects: 100% (9/9), done. remote: Total 105 (delta 3), reused 0 (delta 0), pack-reused 94 Receiving objects: 100% (105/105), 2.38 MiB | 2.06 MiB/s, done. Resolving deltas: 100% (28/28), done. 

次に、新しいファイルを確認します。リストに追加の testfolder が表示されます。

ls 

出力:

css images index.html js LICENSE README.md testfolder vendor 

次に、今行った変更をコミットします。

git commit -m "Added the submodule to the project." 

出力:

"Added the submodule to the project." [main 500a12a] Added the submodule to the project. 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 testfolder 

このコマンドを使用して、変更をリモートリポジトリにプッシュします。

git push 

出力:

Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 429 bytes | 429.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To github.com:KEVINAMAYI/AkanNameGenerator.git 3300a2a..500a12a main -> main 

これで、リモートリポジトリにサブモジュール testfolder が追加されました。

サブモジュールを使用してリポジトリのクローンを作成する

サブモジュールと一緒にリポジトリのクローンを作成します。

git clone --recurse-submodules -j8 git@github.com:KEVINAMAYI/AkanNameGenerator.git 

出力:

Cloning into 'AkanNameGenerator'... remote: Enumerating objects: 108, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (11/11), done. remote: Total 108 (delta 4), reused 3 (delta 1), pack-reused 94 Receiving objects: 100% (108/108), 2.38 MiB | 1.86 MiB/s, done. Resolving deltas: 100% (29/29), done. Submodule 'testfolder' (git@github.com:KEVINAMAYI/AkanNameGenerator.git) registered for path 'testfolder' Cloning into '/home/kevin/tqt/AkanNameGenerator/testfolder'... remote: Enumerating objects: 108, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (11/11), done. remote: Total 108 (delta 4), reused 3 (delta 1), pack-reused 94 Receiving objects: 100% (108/108), 2.38 MiB | 1.55 MiB/s, done. Resolving deltas: 100% (29/29), done. Submodule path 'testfolder': checked out '3300a2aa47ef2c490c19541c6907117511eabe08' 
チュートリアルを楽しんでいますか? <a href="https://www.youtube.com/@delftstack/?sub_confirmation=1" style="color: #a94442; font-weight: bold; text-decoration: underline;">DelftStackをチャンネル登録</a> して、高品質な動画ガイドをさらに制作するためのサポートをお願いします。 Subscribe

関連記事 - Git Clone