Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git repository inside another git repository

I have the following directories structure:

  • g1/
    • .git
    • a
    • b
    • c/
      • .git
      • d
      • e

As you can see, I have de repository "c" inside repository "g1". When I use the following command:

git clone g1 g2

I only get the following directories structure:

  • g1/
    • .git
    • a
    • b
    • c/

The directory "c" remains empty. Any ideas?

like image 500
beagleknight Avatar asked Aug 11 '10 09:08

beagleknight


People also ask

Can you put a Git repository inside another Git repository?

Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

Can Git repositories be nested?

Git allows you to include other Git repositories called submodules into a repository. This allows you to track changes in several repositories via a central one. Submodules are Git repositories nested inside a parent Git repository at a specific path in the parent repository's working directory.

Can you clone a repo inside another repo?

Just for the record, you can clone a git repo within another one: Everything under your lib directory will be ignored by the enclosing Git repo, because said lib directory contains a . git . That means cloning the enclosing repo, and you will get an empty " lib/ " folder.


1 Answers

Submodules (discussed in the Pro Git Book), helps manage repositories nested within a main repository:

Submodules allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.

They are not to be confused with remotes, which are meant mainly for branches of the same project; submodules are meant for different projects you would like to make part of your source tree, while the history of the two projects still stays completely independent and you cannot modify the contents of the submodule from within the main project.

Submodules maintain their own identity; the submodule support just stores the submodule repository location and commit ID, so other developers who clone the superproject can easily clone all the submodules at the same revision.

like image 64
Jungle Hunter Avatar answered Sep 17 '22 18:09

Jungle Hunter