Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git repository in a Git repository

Tags:

git

I have a Git repository including a Git repository.

repo1/      .git/      files      repo2/           .git/           files      files 

Is it possible to work with this architecture?

like image 377
MP0 Avatar asked May 12 '11 16:05

MP0


People also ask

Can you have a Git repository in a 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.

What is a repository in a Git?

A Git repository tracks and saves the history of all changes made to the files in a Git project. It saves this data in a directory called . git , also known as the repository folder. Git uses a version control system to track all changes made to the project and save them in the repository.

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.


2 Answers

You can have nested git repos:
The parent repo will simply ignore nested repo.

jleedev comments and illustrates with this gist script that the parent repo would track the nested repo state through a gitlink.
(gitlink = SHA-1 of the object refering to a commit in another repository. Git links can only be specified by SHA or through a commit mark.
A gitlink has a special mode '160000', used for submodules, but also present for simple nested repos).

However, usual commands would not acknowledge the nested repo: add or commit would apply only in one repo, not the other.

git submodule would allow to reference the nested repo from the parent repo, and keep an exact reference of the child repo.

Another alternative could involve:

  • two separate Git repos (not nested)
  • a symlink from one to a specific part of the other (both Unix, but also Windows Vista+ have symlinks)
like image 150
VonC Avatar answered Oct 18 '22 14:10

VonC


You are trying to accomplish something called a "submodule".

Please check out Git Tools - Submodules to find out how it's working.

like image 35
Artusamak Avatar answered Oct 18 '22 13:10

Artusamak