Skip to content

Instantly share code, notes, and snippets.

@amonks
Last active March 17, 2016 00:34
Show Gist options
  • Save amonks/13583eb22bc6b1372ffd to your computer and use it in GitHub Desktop.
Save amonks/13583eb22bc6b1372ffd to your computer and use it in GitHub Desktop.

using github pages

github pages is free website hosting from github.

Here's the gist: if you have a github repository with a branch called "gh-pages" (instead of the usual "master"), it'll get hosted at http://yourname.github.io/repository. (If you hear the word "branch" and you're like "uh oh", don't worry).

For example, the file 404.html in this repository: https://github.com/amonks/404

is hosted at this url: http://amonks.github.io/404/404.html

also:

  • the bottom of this page has an introduction to some other git stuff
  • this video talks about what git does in general without getting into too many details

hold on what are branches?

remember that git can not only keep track of multiple changes to a project over time, but can also track multiple independent versions of a project, each with their own change histories. They're called branches.

Maybe a branch called master has the stable 'download this' version of a thingy, and a branch called develompent has some new features that don't work quite right yet. Maybe the thingy's documentation website is in a branch of the same repository called gh-pages.

When you use the command line to switch between branches, git changes the files in the folder on your computer to look like the most recent commit of the branch you're switching to. We call switching to a branch like this "checking out" that new branch.

Git has a bunch of cool tools for moving and merging commits (code) between branches, but I won't go into that here.

set it up

If you're in the "master" branch of an existing repository, and you'd like to create a new "gh-pages" branch with the same content, you can use this command:

# checkout is for switching branches. the "-b" makes a new branch.
git checkout -b gh-pages

Then, to push that new "gh-pages" branch to github, use this command:

# this is just like how you would have used `git push origin master` before
git push origin gh-pages

To switch back over to the master branch, commit any new changes then use this command:

git checkout master

If you'd like to stick with Github Pages, you can delete the old master branch from your computer this command:

git branch -d master

You can't delete the master branch from Github, though, if it's still the "Default Branch". You can change the default branch in the settings page on Github.

In this example, it's at https://github.com/amonks/404/settings/branches.

Once you've done that, you can use this command to actually delete the master branch:

git push origin :master

additional resources:

You can also point your own domain name to a site hosted on Github Pages. Read about that on github help

Before github pages, I used nearlyfreespeech.net as a cheap host for static sites.

Today, when I want to host a static site but I have fancier performance needs, I use amazon s3. It's honestly pretty daunting, but it's what "the pros" use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment