当前位置: 动力学知识库 > 问答 > 编程问答 >

Git remote with multiple sub projects

问题描述:

I have a group of projects/modules that are related enough that i want them in the same repository but they live accross multiple directories locally on my machine. Is there a way I can add them as sub directories in a remote repository?

this is how i would normally add a remote

git remote add origin ssh://[email protected]:2227/usr/local/git_root/foo_project.git

would something like this work

git remote add origin ssh://[email protected]:2227/usr/local/git_root/foo_project.git/A

网友答案:

Use submodules:

  • Create a repository for each module/project
  • Create a repository for the main project that will contain them
  • Add the modules/projects to the main repository as submodules:
    git submodule add ssh://[email protected]:2227/module1 module1/
网友答案:

You would do it the other way around. Git repositories are very cheap, so you usually create a new repository for each subproject if they are not directly dependent on each other. This also makes for a cleaner history as when one is working on project A, he does not get involved with all the changes that happened in project B.

So, you would maybe do it like this:

ssh://[email protected]:2227/usr/local/git_root/foo_project/a.git
ssh://[email protected]:2227/usr/local/git_root/foo_project/b.git

If you have one “master” project that should link them all, then submodules are a good choice. You would set up the master project and add a submodule for each subproject. That way you would have the complete project contained in the master project but would still be able to work independently on the subprojects.

分享给朋友:
您可能感兴趣的文章:
随机阅读: