Git Pages: How to link a script file (or any other files) from a branch into the main branch

28 views Asked by At

I am new to github & git pages!
I have an assets branch to store files like css, scrpts, photos, etc. To keep everything organized and free of "clutter" from my main branch, which is the one I am using to "serve" the pages.

How can I link a script file into my html from the main branch? So far the links I get from the assets branch are to the repo not for good for html.

For example, the file BackgroundModule.js from my assets branch is located here: scripts/BackgroundModule.js

And this is the link to my main branch: https://omarjuvera.github.io/Portfolios/

If possible, I would like the link to be structured like this: https://omarjuvera.github.io/Portfolios/assets/scripts/BackgroundModule.js while keeping each branch intact

1

There are 1 answers

1
Rami Assi On

You need to link to the raw file content. Github provides the actual file content under this domain https://raw.githubusercontent.com

I have checked your github profile and prepared this link to the BackgroundModule.js as an example.

Example raw file content link: https://raw.githubusercontent.com/omarjuvera/Portfolios/assets/scripts/BackgroundModule.js

Sample link to the script in your html document:

<script src="https://raw.githubusercontent.com/omarjuvera/Portfolios/assets/scripts/BackgroundModule.js"></script>