Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share files across folders or repositories

I'm working on a code snippet which has to work across multiple themes.

Let's say I have three themes:

  • Orange
  • Green
  • Blue

Every theme has a folder called "snippets" inside, and I put my code snippet there.

  • Orange/snippets/code.html
  • Green/snippets/code.html
  • Blue/snippets/code.html

The "code.html" file is exactly the same across every theme. I keep track of it in its own GitHub repo and then copy and paste to every theme repo.

How can I edit this snippet in one place and be sure that it gets updated in all themes? I'm looking for a method that would be scalable, as soon the number of themes may grow till 20-30.

In my situation I have more files then an example with "code.html" - they are in two folders, and the total amount is around 10.

I was reading about Git submodules, but I don't feel confident like they fit my issue. I'm not sure if this issue is related to Git at all, sorry about that.

P.S. I'm working on SaaS - Shopify to be exact. So any kind of PHP tricks will not work in this case. I need files to be processed in some way locally.

Edit: Real life example:

I have those 4 files:

{{ theme }}/snippets/file1.liquid
{{ theme }}/snippets/file2.liquid
{{ theme }}/assets/file3.liquid
{{ theme }}/assets/file4.liquid

I cannot create sub-directories or other directories.

like image 869
curious Avatar asked Nov 15 '18 20:11

curious


People also ask

How do I share codes across 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.

What is difference between folder and repository?

The repository is essentially the . git hidden folder inside the working directory (workspace). The working directory (workspace) is essentially your project folder. Also note the term directory is basically synonymous to the term folder.


1 Answers

Let say you have your common code in a repository. You could create a submodule in <Theme>/snippets/common. And keep it updated to the latest master every time you want to build/deploy your theme.

That means your code.html will be in <Theme>/snippets/common/code.html

cd <Theme>/snippets

# To add the submodule 
git submodule add <common code repository> common
# 2 new files will be added to the repository
# .gitmodules and the "common" folder

# When you clone the repo in another machine
# Always do the following command 
# to get the files from the common repository
git submodule update --init

# If you made a change in the common repository
git submodule update --remote
like image 186
Julio Daniel Reyes Avatar answered Sep 23 '22 14:09

Julio Daniel Reyes