GitHub Pages – Publish Subfolder to GitHub Pages Keeping Subfolder Path

githubgithub-pages

I have a repository called, let's say, odds-and-ends. Within that repo is the folder, js-projects, and then another folder within that is quick-js-app. quick-js-app contains all the ingredients of a basic web page, including an index.html, CSS and JS file, etc.

It's quite easy to publish the subdirectory quick-js-app to GitHub pages (for example, this gist by cobyism tells how to do so).

But, is it possible to publish quick-js-app so that it retains the file path, i.e., it would be located at http://myusername.github.io/odds-and-ends/js-projects/quick-js-app?

(Note, someone asks about this here within the gist thread from above – Gulp is suggested as a solution, but I didn't have any luck with it.)

Does anyone have a suggestion for me?

Best Answer

If branch gh-pages already exists, delete it.

git branch -D gh-pages

Create a new branch gh-pages without any content.

git checkout --orphan gh-pages

Remove all initially cached files from the index.

git rm -r --cached .

Add, commit, and push js-projects/quick-js-app. If gh-pages is already on github, you need to force the push using -f. Be aware that this deletes all already existing content in different directories like js-projects/complex-js-app.

git add js-projects/quick-js-app
git commit -m "Publish"
git push [-f] origin gh-pages