I have a main repo (repo 1) that I work with. I have another repo (repo 2) that needs to fit into the first one and I'm not sure how I could have them both in the same folder. The idea is that I have a standard codebase that I need in each project - yet each project is it's own 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 of the folder structures do. So sometimes certain folders from one repo will be in the other repo.
How can I work so these two repositories build the complete codebase?
UPDATE
Both git repos exist in the same root project folder level. They cannot be submodules since they cross back and forth through each other as shown above. They are not separate folders.
UPDATE 2
Wait, maybe this is easier than I thought. Can you clone a standard codebase repo and then create a new branch that is your project and then just keep merging that branch with the codebase repo each time it changes?
To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.
If you have separate accounts for work and personal use, you can merge the accounts. Tip: We recommend using only one personal account to manage both personal and professional repositories. Warning: Organization and repository access permissions aren't transferable between accounts.
Edit: In order to have two .git directories, when you init them, there would be some extra work. When you init, do:
git --git-dir=.git1 --work-tree=. init
git --git-dir=.git2 --work-tree=. init
Now you have two git dirs in the same directory. Not very pretty. At this point, make sure that you have .git1 and .git2 in both .gitignores, since they aren't ignored by default. Additionally, every git command you run must also have the --git-dir argument to specify which repository you're interacting with. You could setup aliases for that.
Since they're in the same base directory and submodules won't work, you could put '.gitignore' files inside both '.git/info/exclude' directories. Putting them in .git/info/exclude makes sure that the other repo doesn't pick up the exclusions.
It may take some maintenance if the two repos differ by a finer granularity than folders, but if you specify in each .gitignore the files that belong only to the OTHER repo, it should work.
See: gitignore
Use git submodule
Update:
The standard code base that needs to be a part of all the repos has to be a seperate distinct git repository.
git submodule add <repo_nick_name> <repo_path>
will add that repo to this one. On cloning and pushing, only the .gitmodules
file and the hash at the repo will be pushed/cloned.
git submodule init
and
git submodule update
respectively initializes and updates the remote submodule repos.
For detailed info, check the git community book documentation on git submodules and/or scot chacon's screencast on the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With