这是我的例子。
让我们为每个私人存储库生成密钥。
user@linux:~/.ssh$ cd $HOME/.ssh && ssh-keygen -t ed25519 -f "myMother_key" -N "" -C "myKeyForGitHubMother" <<< $'\ny' >/dev/null 2>&1
user@linux:~/.ssh$ cd $HOME/.ssh && ssh-keygen -t ed25519 -f "myBaby_key" -N "" -C "myKeyForGitHubBaby" <<< $'\ny' >/dev/null 2>&1
通过 FireFox 我打开
github.com
并手动将 myMother_key.pub
文件添加到 [email protected]:AndreiCherniaev/mother.git
存储库(允许写入访问复选框是)和 myBaby_key.pub
到 [email protected]:AndreiCherniaev/baby.git
(允许写入访问复选框是)
我在一台服务器上使用多个存储库所以我的
~/.ssh/config
文件包含
Host babysubdomain.github.com
HostName github.com
User git
IdentityFile ~/.ssh/myBaby_key
IdentitiesOnly yes
Host mothersubdomain.github.com
HostName github.com
User git
IdentityFile ~/.ssh/myMother_key
IdentitiesOnly yes
其中
babysubdomain.
mothersubdomain.
是任何文本。
让我们克隆baby repo。
user@linux:~$ git clone [email protected]:AndreiCherniaev/baby.git
只是为了好玩,让我们添加任何公共存储库作为 Baby 的子模块。在我的示例中,我将使用 Buildroot 项目
user@linux:~$ cd baby
user@linux:~/baby$ git submodule add -b master https://github.com/buildroot/buildroot myBuildroot/buildroot
user@linux:~/baby$ git commit -m "add submodule myBuildroot/buildroot/ to baby"
user@linux:~/baby$ git push
让我们回到
Download/
并克隆 mother
存储库
user@linux:~/baby$ cd ..
user@linux:~$ git clone [email protected]:AndreiCherniaev/mother.git
user@linux:~$ cd mother
让我们将子模块添加到
mother
存储库
user@linux:~$ cd mother/
user@linux:~/mother$ git submodule add -b main [email protected]:AndreiCherniaev/baby.git
user@linux:~/mother$ git commit -m "add submodule baby to mother"
user@linux:~/mother$ git push
现在让我们从您的电脑中删除 mother/ 的本地副本
user@linux:~/mother$ cd ..
user@linux:~$ rm -Rf mother/
让我们用buildroot克隆妈妈和宝宝
git clone --recurse-submodules -j8 [email protected]:AndreiCherniaev/mother.git
现在我们有了 repo mother 和子模块 Baby 以及子模块 myBuildroot/buildroot/