How to deploy only your dist folder to the gh-pages branch (Github Pages)


If you do a lot on GitHub, you probably know what GitHub Pages are. In case you don’t:

On Github Pages you can host an HTML, CSS & JavaScript website. Simply create an branch called: gh-pages, wait a few minutes and you can find it with this url <github-username>/<github-repo-name>.

Only deploy your dist folder to Github Pages

When you’re working with a handy taskrunner like GruntJS or GulpJS, then you may have a dist folder containing your optimised files. Grunt & Gulp have their own plugins to deploy to Github Pages:

But you can also create a simple batch script (if you’re a Windows user) or shell script (if you’re a Mac or Linux user). The only code you have to add is:

git subtree push --prefix dist origin gh-pages

If you think there is an faster way to deploy a dist folder to Github Pages, let me know in the comments!

Download the batch & shell scripts I created as an example. Hosted on Github.



  • Alex says:

    This is awesome! I seriously use this command all the time. I set up an alias so I don’t have to remember it everytime:

    git config –global ‘subtree push –prefix dist origin gh-pages’

    Now everytime I type ‘git gh-pages’ it automatically updates my GitHub pages. Thank you!

  • Danilo Prates says:

    How would you deal on a case it uses the master branch, like in sites?

you might also like