子模块可以是任何你喜欢的仓库,但如果你想本地添加它,你需要一个支持的协议。
在上面的链接中,第一个描述的协议是本地协议(Local protocol)
,它允许你使用路径(path)
或file://
来克隆(clone)
。
Local Protocol
The most basic is the Local protocol, in which the remote repository is in another directory on disk.
This is often used if everyone on your team has access to a shared filesystem such as an NFS mount, or in the less likely case that everyone logs in to the same computer.
The latter wouldn’t be ideal, because all your code repository instances would reside on the same computer, making a catastrophic loss much more likely.
If you have a shared mounted filesystem, then you can
clone
,push
to, andpull
from alocal file-based repository
.To
clone
a repository like this or to add one as a remote to an existing project, use thepath
to the repository as the URL.For example, to clone a local repository, you can run something like this:
git clone /opt/git/project.git
Or you can do this:
git clone file:///opt/git/project.git
Git operates slightly differently if you explicitly specify
file://
at the beginning of the URL.If you just specify the path, Git tries to use hardlinks or directly copy the files it needs.
If you specify
file://
, Git fires up the processes that it normally uses to transfer data over a network which is generally a lot less efficient method of transferring the data.The main reason to specify the
file://
prefix is if you want a clean copy of the repository with extraneous references or objects left out – generally after an import from another version-control system or something similar (see Git Internals for maintenance tasks). We’ll use the normal path here because doing so is almost always faster.
To add a local repository to an existing Git project, you can run something like this:
git remote add local_proj /opt/git/project.git
Then, you can push to and pull from that remote as though you were doing so over a network.