How do you merge two git repositories?

I have a main repo (repo 1) that I work with. I have another repo (repo 2) that should fit in the first one, and I'm not sure how I could have both of them in the same folder. The idea is that I have a standard code base that I need in every project, but every project is the property of git repo.

/project
    /.git(repo 2)
    /.git(repo 1)
    /repo_2_sub
        /repo_2_sub_sub
            /repo_1_sub_sub
    /repo_1_sub
        /repo_1_sub_sub
        /repo_2_sub_sub

None of the files overlap, but some folder structures. Therefore, sometimes some folders from one repo will be in another repo.

How can I work so that these two repositories build a complete code base?

UPDATE

Both git repositories exist at the same level as the project root files. They cannot be submodules, since they intersect with each other, as shown above. They are not separate folders.

UPDATE 2

, , , . , , , , ?

+5
3

, , , . codebase repo, , , codebase repo , ?

. , . . , , . master .

. origin/master master .

+1

git submodule

Update:

, , git.

git submodule add <repo_nick_name> <repo_path>

. , .gitmodules /.

git submodule init

git submodule update

.

git git / scot-scot-scot scotencast .

+2

: , .git, , . , :

git --git-dir=.git1 --work-tree=. init
git --git-dir=.git2 --work-tree=. init

git dirs . . , .git1 .git2 .gitignores, . , git, , - git -dir, , . .

Since they are in the same base directory and the submodules will not work, you can put the ".gitignore" files in both the ".git / info / exclude" directories. Putting them in .git / info / exclude ensures that the other repo does not receive exceptions.

Some maintenance may be required if the two repositories are more granular than folders, but if you specify files related to OTHER REPO only in each .gitignore, it should work.

See: gitignore

+2
source

All Articles