Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created October 4, 2012 19:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ramnathv/3835752 to your computer and use it in GitHub Desktop.
Save ramnathv/3835752 to your computer and use it in GitHub Desktop.
Automating Github Pages Workflow

Problem

You have git repository with the following directory structure

myproject
|- source
|- docs
|- README.md

You want to deploy the docs directory to the gh-pages branch.

Solution

Step 1 Setup Github Pages Branch with Docs

git checkout -b gh-pages
ls | grep -v docs | xargs rm -rf
git mv docs/* .
git commit -a -m 'initial commit on gh-pages branch
git checkout master

Step 2 Update Github Pages Branch

git checkout gh-pages
git merge -s subtree master
git checkout master

Note. Step 2 can be automated by throwing the commands into a post-commit hook. Here is how to do it

mate .git/hooks/post-commit
# create a bash script with commands from Step 2
chmod +x .git/hooks/post-commit # make the script executable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment