问题描述
我在github上有一个图书馆
my_library
|-- my_submodule
与.gitmodules
[submodule "my_submodule"]
path = my_submodule
url = ../my_submodule.git
branch = master
我的贡献者现在需要将repo my_library
和repo my_submodule
都分叉到他们的github,然后才能git clone --recurse-submodules https://github.com/<contributor_user_name>/my_library
否则他们会得到
...
Submodule 'my_submodule' (https://github.com/<contributor_user_name>/fastai-docs.git) registered for path 'docs'
cloning into 'my_submodule'...
Username for 'https://github.com': <contributor_user_name>
Password for 'https://<contributor_user_name>@github.com':
remote: Repository not found.
fatal: repository 'https://github.com/<contributor_user_name>/my_submodule.git/' not found
fatal: clone of 'https://github.com/<contributor_user_name>/my_submodule.git' into submodule path 'my_submodule' Failed
我应该怎么做,所以贡献者也不需要分叉my_submodule
?
解决方法
如果您指定相对路径作为子模块的URL,则Git将假定子模块的存储库在与主存储库相同的位置上可用。
如果相对于超级项目的存储库给出了URL,则假定超级项目和子模块存储库将放置在相同的相对位置,并且仅需提供超级项目的URL。 git-submodule将使用
.gitmodules
中的相对URL正确定位子模块。
如果您不希望贡献者也必须克隆子模块的存储库,则应在.gitmodules
中指定其绝对URL:
[submodule "my_submodule"]
path = my_submodule
url = https://github.com/<your_user_name>/my_submodule.git
branch = master
这样,Git将从您的GitHub帐户而不是他们的GitHub帐户中获取子模块的存储库。
,您提交了一个.gitmodules
文件,其中url
是相对于根回购源的。
以相对URL替换此相对URL到您的仓库:https://github.com/RichardYY/fastai-docs.git
用户(包括您自己)可以使用git config url.[replacement url].insteadOf
(this gist中的示例)连接到其本地克隆上的其他存储库:
# for example : if you want to access this repo through ssh on your local clone :
git config url."[email protected]:RichardYY/fastai-docs.git".insteadOf https://github.com/RichardYY/fastai-docs.git