in Code

GitHub Pages + JavaScript = Awesome

February 2, 2013

One of the coolest things I've learned of recently is GitHub Pages. GitHub hosts most of the world's code by now, and could just sit back and do nothing, but they constantly keep updating and improving things (have you looked at Gists recently?). With GitHub Pages, anything you put in your "gh-pages" branch and upload to GitHub will be hosted on [username].github.com/[repository]. Most have used this for documentation, but if you have an application that only requires static file hosting, then you can host your entire application via GitHub for free. I'm not recommending you do this for production or anything, but for side projects it's an excellent way to show a running example of the code without requiring the user download and run it locally.

To use, simply perform the following commands:

git checkout -b gh-pages
git rebase master
git push origin gh-pages

(make sure to "git checkout master" to continue coding)

The first time you do this, GitHub will state it takes about 10 or so minutes to push out the code. But once done, you've got a running demo of your application. I've been using this for all my JavaScript projects on GitHub, and it's been great, no problems. This has made things like Heroku and Cloud Foundry less of a necessity and had me trying to use Local Storage and Session Storage for persistance more often.