I have a git repository containing a Visual Studio solution with several projects. I have another git repository (also VS) where I want to add one of the projects in the first repo:
Repo 1:
Project_1
Project_2
Project_3
Repo 2:
Project_4
Project_5
Project_1 (Same as Project_1 above)
Is it possible to share just one of the projects in the git repo with another git repository? When I work in the second repo I want to be able to do commit/pull/push to the project that belongs to the first repo, and when I open the first repo I want to be able to get the changes I made to the first project in the second repo.
I have looked at git submodules
but I don´t think that would help me since I don´t want to extract the shared project from the first git repo into a separate one. I want to keep the first repo intact...
I think you may be confused on the structure of a git
repository. The way I would structure your project is to make a repository for each of the projects then add them to Repo 1
and Repo 2
super projects.
Graphically
Git # Main git project directory
/Projects
/Project_1 # Each one is its own Git repository
/Project_2
/Project_3
/Project_4
/Project_5
/Repos # The main repositories that utilize the projects
/Repo_1 # The super project directory
.gitmodules # The .gitmodules file created by 'git submodules add'
--> submodule with url=../../Projects/Project_1 # entry in .gitmodules
--> submodule with url=../../Projects/Project_2
--> submodule with url=../../Projects/Project_3
/Repo_2
.gitmodules
--> submodule with url=../../Projects/Project_1
--> submodule with url=../../Projects/Project_4
--> submodule with url=../../Projects/Project_5
Since the submodule
urls for Project_1
point to the same location, when you git push
in one of the submodule
directories for Repo_1
or Repo_2
you're actually pushing the changes to the same project repository.
There are some gotchas about synchronizing changes across the two super projects as git
allows for the same submodule
in two different super repositories to point to different revisions. For more information (such as how to push, commit changes and update submodules
) I recommend you checkout:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.