Complete question rewrite
So I thought I was explaining this question very simply and direct but it seems I oversimplified to much, so here is a
What's the problem with the hook script you wrote ? What were the contents of the branch gh-pages when you created it?
I had created an empty branch gh-pages with below command:
git checkout --orphan gh-pages
git rm -rf .
touch README.txt
git add README.txt
git commit -m "Initial commit"
git push -u origin gh-pages
Then I ran below script as a part of post-receive hook and it worked for me.
#!/bin/bash
branch=`git rev-parse --abbrev-ref HEAD`
if [ "master" == "$branch" ]; then
git fetch && git checkout gh-pages
git checkout master -- gh-pages
git add -A
git commit -m "Updating project website from 'master' branch."
git push -u origin gh-pages
fi
done