Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a git repository that contains another git repository

I have created a bare git repo (lets call it repo #1) and cloned it.

  • In the clone (repo #2) I have created several folders, one of which I have decided to make a git repo (repo #3).
  • When I commit to repo #2, everything runs as expected exept that repo #3 is ignored (the .git folder, the files commit).

How can I add repo #3 to repo #2 so that when I push repo #2 to repo #1, I can make a seperate clone of repo #1 in which I can also access the history etc. of repo #3?

In other words. How do I create a git repository that contains another git repository?

like image 513
Peter Horne Avatar asked Sep 10 '09 09:09

Peter Horne


People also ask

Can a Git repository contain 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 I have nested Git repositories?

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 create a repository within a repository?

So you can just add a repo within your repo and work on it. You might have to ignore the inner repo folder pychargify however. Submodules are needed when you want to share the repo with others who will be cloning it etc.

How do I clone a Git repository to another Git repository?

Navigate to the repository you just cloned. Pull in the repository's Git Large File Storage objects. Mirror-push to the new repository. Push the repository's Git Large File Storage objects to your mirror.


1 Answers

I don't know how to do exactly what you are suggesting, but sub-modules probably come close (or as close as you are going to get). Here is a decent tutorial:

http://git.or.cz/gitwiki/GitSubmoduleTutorial

like image 67
aaa90210 Avatar answered Nov 09 '22 19:11

aaa90210