6

Assume I have a repository named Shared Features on remote and local.

I want to add this repo to another git repo as a submodule, but instead of using the remote one, I want to use the local one (for bandwidth reasons).

So I want to use this local repo as somewhat a proxy between submodule and remote repo. Is this possible?

Thanks in advance.

Note: I would be very much appreciated if you tell me how to do this in SourceTree as well.


Edit: I think I lack the terminology to make my question clear, so here I draw what I mean: enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167

1 Answers1

5

Submodule can be any repository you like, but if you like to add it locally you will need a supported protocol for that.

In the above link the first described protocol is the Local protocol which allow you to clone using path or file://

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, and pull from a local file-based repository.

To clone a repository like this or to add one as a remote to an existing project, use the path 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.

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167