Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing code between two different git projects

I have two different .Net projects, hosted on github.

I would like to create a shared "commons" library for the two projects.

How should I structure my repository to facilitate this sharing?

Ideally, a change in this common library in one project could easily be pushed into the other project. I prefer to keep the code itself editable from the two projects (within Visual Studio), and not include it as a library. Are there best practices for this?

like image 270
ripper234 Avatar asked Apr 03 '10 12:04

ripper234


People also ask

How do I share code between git repositories?

By using git submodules , you can have an independent repository inside a parent repository. So you have your web and mobile repository and then inside it, in a folder, the shared code repository. If you cd into the shared code folder, you can pull, commit, make branches and push back to the shared code.

Can I add multiple projects in one repository?

Yes. You can put multiple projects in one Git repository but they would need to be on different branches within that repo. The Git console in ReadyAPI gives you the ability to create or switch branches from the UI.

Can you share projects on GitHub?

Once you finished setting up your project and are ready to share it and its history publicly on GitHub, go to Git > GitHub > Share Project on GitHub. You can use IntelliJ IDEA to create a local Git repository and then share the project on GitHub by going to VCS > Share project on GitHub in the menu.


2 Answers

You can use the Git submodules: https://git-scm.com/book/en/v2/Git-Tools-Submodules

like image 91
Esko Luontola Avatar answered Oct 05 '22 20:10

Esko Luontola


Git submodules is probably not your answer. See this blogpost that goes into further details: http://blogs.atlassian.com/2013/05/alternatives-to-git-submodule-git-subtree/

like image 42
Emil Kantis Avatar answered Oct 05 '22 18:10

Emil Kantis