git 如何在 GitHub 中创建嵌套存储库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35043733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:44:25  来源:igfitidea点击:

How do I create nested repositories in GitHub?

gitgithubrepositorygit-submodules

提问by SparkAndShine

I am able to create a repository via https://github.com/(say repo) and have:

我可以通过https://github.com/(比如repo)创建一个存储库,并且有:

https://github.com/username/repo.git

How do I create another repository (say sub_repo) placed under repoand expectedly have:

我如何创建另一个存储库(比如sub_repo)放置在下面repo并预期有:

https://github.com/username/repo/sub_repo.git

采纳答案by MrTux

GitHub does not allow nested repositories (IIRC Git doesn't allow this for bare repositories).

GitHub 不允许嵌套存储库(IIRC Git 不允许对裸存储库执行此操作)。

However, you can use submodules to nest repositories on the "client side" in the working tree.

但是,您可以使用子模块在工作树的“客户端”上嵌套存储库。

You need to clone the parent directory.

您需要克隆父目录。

Then, add the sub-repository as a submodule:

然后,将子存储库添加为子模块

git submodule add https://github.com/username/sub_repo.git

The sub_repo module will then be linked to the parent repo and can be found in the sub_repo directory.

然后 sub_repo 模块将链接到父仓库,并且可以在 sub_repo 目录中找到。

Commit (.gitmodules and sub_repo), push and you're done.

提交(.gitmodules 和 sub_repo),推送就完成了。

回答by max630

github does not support nesting repositories. If you don't want to have absolute urls for submodules the custom is to place them next to super-repository and use "../" in urls, like here: https://github.com/losalamos/cinch-nested-example/blob/d59c26a89153148ba29d68dd5ee455a88efbc9a2/.gitmodules

github 不支持嵌套存储库。如果您不想为子模块提供绝对 url,则自定义是将它们放在超级存储库旁边并在 url 中使用“../”,例如:https: //github.com/losalamos/cinch-nested-示例/blob/d59c26a89153148ba29d68dd5ee455a88efbc9a2/.gitmodules