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.
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