Skip to content

Instantly share code, notes, and snippets.

@dwayne
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwayne/5db2de935d35ec73426a to your computer and use it in GitHub Desktop.
Save dwayne/5db2de935d35ec73426a to your computer and use it in GitHub Desktop.
A workflow for using GitHub project pages to host a static site.

First Time

The gh-pages branch does not exist on the remote.

# Set up the build directory on an orphan branch
$ mkdir build && cd build
$ git init
$ git checkout --orphan gh-pages

# Seed the repository
$ echo 'Hello, world!' > index.html
$ git add .
$ git commit -m "Initial commit"

# Publish the branch
$ REMOTE_URL=`cd .. && git config --get remote.origin.url`
$ git remote add origin $REMOTE_URL
$ git push origin gh-pages

Other Times

The gh-pages branch is already on the remote.

# Checkout the branch
$ mkdir build && cd build
$ git init
$ REMOTE_URL=`cd .. && git config --get remote.origin.url`
$ git remote add origin $REMOTE_URL
$ git fetch origin
$ git checkout gh-pages

# Do some work
$ git add --all
$ git commit -m "..."

# Push the changes
$ git push origin gh-pages

References

@dwayne
Copy link
Author

dwayne commented Mar 19, 2015

The command git rev-parse --show-toplevel always returns the absolute path to the .git directory even if you are several directories deep in a git repository.

@dwayne
Copy link
Author

dwayne commented Mar 19, 2015

Remote references are stored in .git/refs/remotes.

@dwayne
Copy link
Author

dwayne commented Mar 19, 2015

You can get the URL of a given remote using git config --get remote.<remote_name>.url, where <remote_name> could be origin for example.

@dwayne
Copy link
Author

dwayne commented Mar 19, 2015

List the remote branches using git branch -r.

@dwayne
Copy link
Author

dwayne commented Mar 19, 2015

Show the abbreviated commit hash of the most recent commit using git log --pretty="%h" -n1.

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