How to share files across folders or repositories

git reference file in another repo
git submodule

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.

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

Adding a folder from one repo to another, Is there a way by which I can copy over the folder by only playing around with Now we have a local repository that contains only the files and  Share Files Quickly and Easily With Dropbox™ Business. Try It Free! Quickly & Easily Transfer Files of Any Size and Works on Any Device or System.

A Php file structure like the one you listed above would work. The snippets folder would essentially be a .php extension file with an include for a shared html file between projects or in your case themes.

How to upload an entire folder?, I clicked on my repo in a browser, then I clicked on Upload Files. I would like to upload There isn't a way to upload an entire folder through the web UI. The easiest way to do If so, can you share the link to it? Also, what file  1. Right-click on the Folder containing Files that you want to share with others and click on Properties. 2. On File properties screen, select the Sharing tab and click on the Share button. 3. On the next screen, select the “User” that you want to share files with. If the User is not available,

Perhaps you can use a bash script that automate this process across your repos. The following script will take all of the file paths that you set in the first variable and find the one modified last. From there it will copy that file unto all the rest of them, add them to the repo, and commit.

#!/usr/bin/env bash

declare -a filePaths=("Orange/snippets/code.html" "Green/snippets/code.html" "Blue/snippets/code.html")
declare newestFile

for file in "${filePaths[@]}"; do
echo "current file is $file"
if [[ "$file" -nt ${newestFile} ]];
echo "newest file is ${newestFile}"

for file in "${filePaths[@]}"; do
if ! [[ "$file" -ef $newestFile ]];
echo "copying ${newestFile} to ${file}"
cp ${newestFile} ${file}
currentDir=`dirname "${file}"`
cd ${currentDir}
git add ${file}
git commit -m 'automatic update commit'

After you've modified the code.hmtl file, you could run this script or make it part of your production pipeline.

Moving a file to a new location, When editing a file, you can choose to move it anywhere within your repository, even if the Using SSH over the HTTPS port · Recovering your SSH key passphrase you send a pull request to the original repository after you commit your change. To move the file into a subfolder, type the name of the folder you want,  You can share either individual files, or a whole folder. Pick a file or folder, right-click, and then choose Share. On the Send Link page, leave the default selection Anyone with the link can view and edit. Type names or email addresses of team members who you want to have access to the folder, and add an optional message.

Adding a file to a repository, You can upload and commit an existing file to a GitHub repository. for deleting or transferring repositories · Restricting repository visibility changes in your Files that you add to a repository via a browser are limited to 25 MB per file. Drag and drop the file or folder you'd like to upload to your repository onto the file tree. Trying to publish a few files from our project to NPM forced us to split our repository and create new ones just to share this code. When dealing with hundreds of components, this meant having to maintain and make changes across hundreds of repositories .

Sharing Code with SVN Externals and Shared Repositories, Learn how to use SVN externals and shared repositories to improve collaboration. Share: Sharing a development codebase among different teams and different create corresponding sub-folders and place the files in the admin tools area. Work with your files wherever you are. OneDrive gives you anywhere access to all your files, seamlessly integrated with Office and pre-installed with Windows. Automatically sync your files to your desktop so you can work with files offline. Access files on Windows, Mac, or mobile devices.

Sharing the same repository between two projects, I'm trying to find out if it's possible to share the same repository between two repos each already have a folder called plugins and it contains files relevant to  Perhaps you can use a bash script that automate this process across your repos. The following script will take all of the file paths that you set in the first variable and find the one modified last. From there it will copy that file unto all the rest of them, add them to the repo, and commit.

  • I think git submodules could do the job but could we have a little more information. For example is the code shared regrouped in a single directory (with sub-directories possibly) or in multiple directories at the root of the theme.
  • @永劫回帰 I added a real-life example. Sub-directories cannot be created.
  • Why not use soft links ?…
  • Thank you for your answer. I updated my question with a real-life example. I cannot create sub-directories. Please check it out.
  • Can you add symbolic links? e.g. to combine it with submodules as this answer suggest
  • If symbolic links will cause you trouble, you could also include a script, to update the submodule and copy/replace the common files
  • git submodules and symbolic links solve the case in my opinion. @curious your example doesn't prove submodules are unusable.
  • Hey, I added "PS"