How to share files across git repositories?

Git

Git Problem Overview


I have several applications across sub domains on various servers Each application has its own git repository. Each application uses several shared files. Essentially, my repos overlap. How is this situation best handled with multiple editors of multiple projects?

Git Solutions


Solution 1 - Git

I would try making all the overlapping parts git submodules.

Solution 2 - Git

As long as the multiple projects are pushing their changes to the submodule up to the shared location, yeah they can all makes changes to the shared resource. That said, if one of them needs theirs to be 'special' they'll have to branch the submodule.

https://git-scm.com/book/en/v2/Git-Tools-Submodules

This walks you through a super project with submodules, editing the submodule from within the super project and pushing it back up. It also shows the one danger which is silently overwriting changes if you run a git submodule update and you had local unpushed changes on master branch.

Specifically, somewhere you've got a shared folder 'folder' - you'll need to remove this from all the git projects, but create a new git repo somewhere with the current contents as the initial commit. Then you'll git submodule <repo> folder; git submodule update in all the projects which will now share it. They'll all be able to push changes up to the shared repo, and will be able to pull down each other's changes.

Solution 3 - Git

It sounds like you should partition the common elements so that there's a clear distinction, then use submodules. Make sure you clearly separate the common pieces, otherwise you'll likely end up with an unmaintainable mess.

Solution 4 - Git

You could also use the git-subrepo tool. The wiki page is linked. It is basically an improved version of submodule and subtree.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontbesedaView Question on Stackoverflow
Solution 1 - GitmckeedView Answer on Stackoverflow
Solution 2 - GitPeteView Answer on Stackoverflow
Solution 3 - GitPeterView Answer on Stackoverflow
Solution 4 - GitXiaodong QiView Answer on Stackoverflow