How do I use git to sync multiple projects?

I have a directory structure:

|-- ROOT
    |-- Project1
    |   |-- application
    |   |-- img
    |   |-- js
    |   |-- css
    |   `-- system
    |
    |-- Project2
    |   |-- application
    |   |-- img
    |   |-- js
    |   |-- css
    |   `-- system
    |-- Project3
    ....

      

The root folder contains a total of x projects: "Project1", "Project2", "Project3", etc.

Now I would like to use git on "system", "css" and "js". These folders must be the same for every project. So how can you keep all projects in sync with git?

I am suppose to create a "Master Project" and make new modifications to it and pull the new version into all other projects. But this pain is ** ..

I would like to run some batch / batch file to sync everything at once. For example, if I have 6 projects and I change something in project 1, how can I quickly get this modification for all projects (instead of clicking Project1 on "Master" and pulling it 5 times)?

Is it possible?

Just for the record, I am working on a windows machine.

Previous question: Git between multiple projects

+3


source to share


2 answers


You will probably still want to use a submodule. See this page in the git book .

Using submodules makes handling the types of changes you're talking about easy enough. Take a look at the second half of this answer , which summarizes the process.



I modified my previous answer, as I see it can be a little painful for multiple projects if you need to keep them all in step, as it will take a while to update all submodulation references in the main project. As per the previous answer I I suggest you script this process if that's what you want to do.

This has the advantage when projects mature, but in my experience it often happens that all projects cannot be updated at once. Sometimes, one project still needs an older version for a period of time. In this case, you can simply update the required projects to reference the new commit in the submodule and then update the others later when you have time.

+5


source


Using git submodule

for these folders (if the main project is another git project) will make it a bit easier, but won't save you the hassle of pulling after pushing.

Writing a bash script that does this for each folder that is a git project or submodule should be pretty straightforward. maybe something like:



find -name css -type d -execdir git pull origin master ;

+2


source







All Articles