Deploying Ignored Dist Folder To GitHub Pages

- 1 answer

I have created a Git repo for a JavaScript library. The repo also contains a demo website that uses the bundled library, which is generated in a dist/ folder. I would now like to deploy that website to GitHub Pages.

However, I have the dist/ folder in my .gitignore and would prefer it to remain ignored.

Is there a way to automatically generate the gh-pages branch, which should include dist/, but keep it off the master branch?



Commit this script and call it after having built your dist:


git commit -am "Save uncommited changes (WIP)"
git branch --delete --force gh-pages
git checkout --orphan gh-pages
git add -f dist
git commit -m "Rebuild GitHub pages"
git filter-branch -f --prune-empty --subdirectory-filter dist && git push -f origin gh-pages && git checkout -

I use it for that ;-)