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.
git version-control workflow
add a comment |
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.
git version-control workflow
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.
– 永劫回帰
Nov 21 '18 at 12:01
@永劫回帰 I added a real-life example. Sub-directories cannot be created.
– curious
Nov 21 '18 at 15:12
Why not use soft links ?stackoverflow.com/questions/954560/…
– Dawid Drozd
Nov 26 '18 at 13:08
add a comment |
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.
git version-control workflow
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.
git version-control workflow
git version-control workflow
edited Nov 21 '18 at 15:11
curious
asked Nov 15 '18 at 20:33
curiouscurious
90214
90214
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.
– 永劫回帰
Nov 21 '18 at 12:01
@永劫回帰 I added a real-life example. Sub-directories cannot be created.
– curious
Nov 21 '18 at 15:12
Why not use soft links ?stackoverflow.com/questions/954560/…
– Dawid Drozd
Nov 26 '18 at 13:08
add a comment |
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.
– 永劫回帰
Nov 21 '18 at 12:01
@永劫回帰 I added a real-life example. Sub-directories cannot be created.
– curious
Nov 21 '18 at 15:12
Why not use soft links ?stackoverflow.com/questions/954560/…
– Dawid Drozd
Nov 26 '18 at 13:08
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.
– 永劫回帰
Nov 21 '18 at 12:01
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.
– 永劫回帰
Nov 21 '18 at 12:01
@永劫回帰 I added a real-life example. Sub-directories cannot be created.
– curious
Nov 21 '18 at 15:12
@永劫回帰 I added a real-life example. Sub-directories cannot be created.
– curious
Nov 21 '18 at 15:12
Why not use soft links ?stackoverflow.com/questions/954560/…
– Dawid Drozd
Nov 26 '18 at 13:08
Why not use soft links ?stackoverflow.com/questions/954560/…
– Dawid Drozd
Nov 26 '18 at 13:08
add a comment |
3 Answers
3
active
oldest
votes
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
Thank you for your answer. I updated my question with a real-life example. I cannot create sub-directories. Please check it out.
– curious
Nov 21 '18 at 15:13
Can you add symbolic links? e.g. to combine it with submodules as this answer suggest stackoverflow.com/a/7597867/4727666
– Julio Daniel Reyes
Nov 21 '18 at 15:31
If symbolic links will cause you trouble, you could also include a script, to update the submodule and copy/replace the common files
– Julio Daniel Reyes
Nov 21 '18 at 15:34
git submodules and symbolic links solve the case in my opinion. @curious your example doesn't prove submodules are unusable.
– noobed
Nov 27 '18 at 10:25
add a comment |
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.
Hey, I added "PS"
– curious
Nov 15 '18 at 20:51
add a comment |
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} ]];
then
newestFile="${file}"
fi
echo "newest file is ${newestFile}"
done
for file in "${filePaths[@]}"; do
if ! [[ "$file" -ef $newestFile ]];
then
echo "copying ${newestFile} to ${file}"
cp ${newestFile} ${file}
currentDir=`dirname "${file}"`
cd ${currentDir}
git add ${file}
git commit -m 'automatic update commit'
fi
done
After you've modified the code.hmtl file, you could run this script or make it part of your production pipeline.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327500%2fhow-to-share-files-across-folders-or-repositories%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
Thank you for your answer. I updated my question with a real-life example. I cannot create sub-directories. Please check it out.
– curious
Nov 21 '18 at 15:13
Can you add symbolic links? e.g. to combine it with submodules as this answer suggest stackoverflow.com/a/7597867/4727666
– Julio Daniel Reyes
Nov 21 '18 at 15:31
If symbolic links will cause you trouble, you could also include a script, to update the submodule and copy/replace the common files
– Julio Daniel Reyes
Nov 21 '18 at 15:34
git submodules and symbolic links solve the case in my opinion. @curious your example doesn't prove submodules are unusable.
– noobed
Nov 27 '18 at 10:25
add a comment |
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
Thank you for your answer. I updated my question with a real-life example. I cannot create sub-directories. Please check it out.
– curious
Nov 21 '18 at 15:13
Can you add symbolic links? e.g. to combine it with submodules as this answer suggest stackoverflow.com/a/7597867/4727666
– Julio Daniel Reyes
Nov 21 '18 at 15:31
If symbolic links will cause you trouble, you could also include a script, to update the submodule and copy/replace the common files
– Julio Daniel Reyes
Nov 21 '18 at 15:34
git submodules and symbolic links solve the case in my opinion. @curious your example doesn't prove submodules are unusable.
– noobed
Nov 27 '18 at 10:25
add a comment |
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
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
answered Nov 21 '18 at 14:50
Julio Daniel ReyesJulio Daniel Reyes
2,102815
2,102815
Thank you for your answer. I updated my question with a real-life example. I cannot create sub-directories. Please check it out.
– curious
Nov 21 '18 at 15:13
Can you add symbolic links? e.g. to combine it with submodules as this answer suggest stackoverflow.com/a/7597867/4727666
– Julio Daniel Reyes
Nov 21 '18 at 15:31
If symbolic links will cause you trouble, you could also include a script, to update the submodule and copy/replace the common files
– Julio Daniel Reyes
Nov 21 '18 at 15:34
git submodules and symbolic links solve the case in my opinion. @curious your example doesn't prove submodules are unusable.
– noobed
Nov 27 '18 at 10:25
add a comment |
Thank you for your answer. I updated my question with a real-life example. I cannot create sub-directories. Please check it out.
– curious
Nov 21 '18 at 15:13
Can you add symbolic links? e.g. to combine it with submodules as this answer suggest stackoverflow.com/a/7597867/4727666
– Julio Daniel Reyes
Nov 21 '18 at 15:31
If symbolic links will cause you trouble, you could also include a script, to update the submodule and copy/replace the common files
– Julio Daniel Reyes
Nov 21 '18 at 15:34
git submodules and symbolic links solve the case in my opinion. @curious your example doesn't prove submodules are unusable.
– noobed
Nov 27 '18 at 10:25
Thank you for your answer. I updated my question with a real-life example. I cannot create sub-directories. Please check it out.
– curious
Nov 21 '18 at 15:13
Thank you for your answer. I updated my question with a real-life example. I cannot create sub-directories. Please check it out.
– curious
Nov 21 '18 at 15:13
Can you add symbolic links? e.g. to combine it with submodules as this answer suggest stackoverflow.com/a/7597867/4727666
– Julio Daniel Reyes
Nov 21 '18 at 15:31
Can you add symbolic links? e.g. to combine it with submodules as this answer suggest stackoverflow.com/a/7597867/4727666
– Julio Daniel Reyes
Nov 21 '18 at 15:31
If symbolic links will cause you trouble, you could also include a script, to update the submodule and copy/replace the common files
– Julio Daniel Reyes
Nov 21 '18 at 15:34
If symbolic links will cause you trouble, you could also include a script, to update the submodule and copy/replace the common files
– Julio Daniel Reyes
Nov 21 '18 at 15:34
git submodules and symbolic links solve the case in my opinion. @curious your example doesn't prove submodules are unusable.
– noobed
Nov 27 '18 at 10:25
git submodules and symbolic links solve the case in my opinion. @curious your example doesn't prove submodules are unusable.
– noobed
Nov 27 '18 at 10:25
add a comment |
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.
Hey, I added "PS"
– curious
Nov 15 '18 at 20:51
add a comment |
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.
Hey, I added "PS"
– curious
Nov 15 '18 at 20:51
add a comment |
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.
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.
answered Nov 15 '18 at 20:41
HappyProgrammingEveryoneHappyProgrammingEveryone
31
31
Hey, I added "PS"
– curious
Nov 15 '18 at 20:51
add a comment |
Hey, I added "PS"
– curious
Nov 15 '18 at 20:51
Hey, I added "PS"
– curious
Nov 15 '18 at 20:51
Hey, I added "PS"
– curious
Nov 15 '18 at 20:51
add a comment |
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} ]];
then
newestFile="${file}"
fi
echo "newest file is ${newestFile}"
done
for file in "${filePaths[@]}"; do
if ! [[ "$file" -ef $newestFile ]];
then
echo "copying ${newestFile} to ${file}"
cp ${newestFile} ${file}
currentDir=`dirname "${file}"`
cd ${currentDir}
git add ${file}
git commit -m 'automatic update commit'
fi
done
After you've modified the code.hmtl file, you could run this script or make it part of your production pipeline.
add a comment |
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} ]];
then
newestFile="${file}"
fi
echo "newest file is ${newestFile}"
done
for file in "${filePaths[@]}"; do
if ! [[ "$file" -ef $newestFile ]];
then
echo "copying ${newestFile} to ${file}"
cp ${newestFile} ${file}
currentDir=`dirname "${file}"`
cd ${currentDir}
git add ${file}
git commit -m 'automatic update commit'
fi
done
After you've modified the code.hmtl file, you could run this script or make it part of your production pipeline.
add a comment |
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} ]];
then
newestFile="${file}"
fi
echo "newest file is ${newestFile}"
done
for file in "${filePaths[@]}"; do
if ! [[ "$file" -ef $newestFile ]];
then
echo "copying ${newestFile} to ${file}"
cp ${newestFile} ${file}
currentDir=`dirname "${file}"`
cd ${currentDir}
git add ${file}
git commit -m 'automatic update commit'
fi
done
After you've modified the code.hmtl file, you could run this script or make it part of your production pipeline.
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} ]];
then
newestFile="${file}"
fi
echo "newest file is ${newestFile}"
done
for file in "${filePaths[@]}"; do
if ! [[ "$file" -ef $newestFile ]];
then
echo "copying ${newestFile} to ${file}"
cp ${newestFile} ${file}
currentDir=`dirname "${file}"`
cd ${currentDir}
git add ${file}
git commit -m 'automatic update commit'
fi
done
After you've modified the code.hmtl file, you could run this script or make it part of your production pipeline.
answered Nov 26 '18 at 15:55
Asinus RexAsinus Rex
163219
163219
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327500%2fhow-to-share-files-across-folders-or-repositories%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
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.
– 永劫回帰
Nov 21 '18 at 12:01
@永劫回帰 I added a real-life example. Sub-directories cannot be created.
– curious
Nov 21 '18 at 15:12
Why not use soft links ?stackoverflow.com/questions/954560/…
– Dawid Drozd
Nov 26 '18 at 13:08