Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I "mount" one github repository as a subfolder of another repository?

I have a github repository named "foo" (or rather "myusername/foo"). Now suppose I want to create a repository named "bar", which uses the code in foo; I could just make a copy of the files, but I don't want to need to pull updates - I want to always see only whatever's in the "foo" repository right now; and not to have commits of "updates from foo". I believe I've noticed some repositories in which subfolders are actually separate repositories; and I know git supports sub-repositories or some such thing. So, can I perform such a "repository mount"? If so, how?

Bonus points if I can have the "mount" at a certain version, or a certain branch, rather than the master

like image 435
einpoklum Avatar asked Feb 04 '17 11:02

einpoklum


1 Answers

Beside the submodules and subtree, depending on your specific needs, you may also want to just have another repository without any logic and management.

In such case, you could place another repository in a subdirectory and add that subdirectory to the .gitignore file.

E.g.

RepositoryA/
  - .gitignore (first option)
  - SomeDir/
    - .gitignore (second option)
    - RepositoryB/

.gitignore (first option)

Add one of these:

  • SomeDir/RepositoryB/
  • **/RepositoryB/

.gitignore (second option)

Add this:

  • RepositoryB/

This way, as I said, does not add any logic/management. It just lets you to use any revision from both repositories without any collision.

like image 123
Andrzej Zabost Avatar answered Sep 19 '22 05:09

Andrzej Zabost