How to share files across git repositories?

0 votes
asked Oct 8, 2009 by tbeseda

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?

4 Answers

0 votes
answered Oct 8, 2009 by mckeed

I would try making all the overlapping parts git submodules.

0 votes
answered Oct 8, 2009 by peter

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.

0 votes
answered Oct 17, 2011 by pete

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.

0 votes
answered Oct 28, 2016 by xiaodong-qi

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

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...