Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintain git repo inside another git repo

People also ask

Can I have a Git repo inside another Git repo?

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 you have a repo inside a repo?

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.

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.

How do I add a Git repo to another?

Go to the repo where you want the other repo to be merged, and run the script. Now push the changes on the master branch to remote/origin. This step may not be required depending on what you are trying to do.


It sounds like you want to use Git submodules.

Git addresses this issue using submodules. 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.


I have always used symlinks to maintain two separate and distinct repos.


Yes, you can do exactly what you're asking with the file hierarchy you drew. Repo-B will be independant and have no knowledge of Repo-A. Repo-A will track all changes in it's own files and Repo-B's files.

However, I would not recommend doing this. Every time you change files and commit in Repo-B you'll have to commit in Repo-A. Branching in Repo-B will mess with Repo-A and branching in Repo-A will be wonky (trouble removing folders, etc.). Submodules are definitely the way to go.


You can use a .gitignore file in the parent A repository (ignoring B), but firstly making sure that the B repository is not currently being tracked: commit the parent .gitignore before adding the second B repository.