Keeping multiple repo subfolders synchronised

Hello all,

I have been around Github for a while now mainly just downloading libraries that others made.

Now, for the first time, I’m using it to manage my own repo. And I have run into the following problem:

In my repo, I have folders A, B, and C. In each of those folders, there is a /scripts/ subfolder, containing some code. These 3 /scripts/ folders and their contents are identical. And they should stay that way.

So, what I want to accomplish is that when I change something in /A/scripts/somecode.cs, the /B/scripts/somecode.cs also gets updated with the latest version.

My current (hopefully temporary) workflow is that I push the changes to A/scripts/ to git. Then merge to main. Then copy A/scripts/ to B/, overwriting the old B/scripts/. Same for C. Then push the changes to git directly into main branch again.

After a lot of searching, I’m starting to have a feeling that this “simple” goal is harder to achieve that I initially thought.

Does anyone have some suggestions on how to tackle this? I was thinking that maybe it’s possible to run an automated custom script after a merge, that checks finds the most recently updated scripts folder and overwrites the other ones with it. But it seems like a crude fix, if at all possible.

Thanks in advance!


Technically, you could probably use an Actions workflow to accomplish that: On push, check if any of those files changed, copy as necessary, and commit. That will however get tricky if the same file changes in different copies of the directory.

However, I’m thinking it’s probably not a good idea to set up the repository with three copies of the same thing. Why not have a shared scripts/ directory, and let all the code in the A/, B/ and C/ directories use that? Or if some other tool requires the scripts to be in those specific locations, have a build step that copies the shared directory there. That way you wouldn’t have to worry about keeping three copies in sync.

Hi, thanks for the swift response.

I will look into the Actions workflow. Seems like that could do the trick in a crude way.

To elaborate a bit on the weird structure:
Every folder (A/ B/ and C/ etc.) stands for a saved (Demo3D) 3d model that has some scripts attached to it. When a user wants to work on model A, he/she opens the .demo3d file in the A/ folder in the 3d editor. And when the changes are saved, the 3d model is saved back to the .demo3d file. And the scripts in the /scripts/ subfolder.

So if we would move all the separate /scripts/ to a centralized location, the user would not be able to open the model, because the /scripts/ folder is not where the software is expecting it. And even if Demo3D could find the /scripts/, it would still save them to the A, B or C subfolder. Not to all of the models.

I’d share the link to the repo, but since it’s private I don’t think you could see it.