I\'m developing a jQuery plugin that\'s being hosting on GitHub. It has a demo included of which I\'m manually copying and pushing to the branch gh-pages, what
I'm adding further explanation to @denbuzze and @MCSDWVL answers.
If you want to push both to master and gh-pages automatically each time you run git push origin, you probably want to add a Refspec to the git config of your repo.
So, according to the git-scm book, you can add two RefSpecs, by adding two push values to the repo config file .git/config:
[remote "origin"]
url = https://github.com/<github_user>/<repo_name>
fetch = +refs/heads/*:refs/remotes/origin/*
push = refs/heads/master:refs/heads/master
push = refs/heads/master:refs/heads/gh-pages
That will cause a git push origin to:
master branch to the remote master branchmaster branch to the remote gh-pages branchby default.
Note: using a + before the spec causes to force push to the repo. Use it with caution:
The format of the refspec is an optional
+, followed by<src>:<dst>, where<src>is the pattern for references on the remote side and<dst>is where those references will be written locally. The+tells Git to update the reference even if it isn’t a fast-forward.
UPDATE: GitHub now allows pages to be published from any branch and directory you want.
It was much easier for me to use the gh-pages branch as master. There's nothing magical about "master"; it's just another branch name. There is something magical about gh-pages, because that's where GitHub is looking for index.html to serve your page.
Read more in my other answer on this topic.
Using gh-pages as master is also easier than subtrees, which are easier than mirroring. You could use git subtree as described here or here: if you have a directory which contains your demo, you can push that directory to the gh-branch with one command. Let's say you name the directory gh-pages to make things clear. Then after you've committed and pushed your changes to master, run this to update gh-pages:
git subtree push --prefix gh-pages origin gh-pages
The problem is if your files in gh-pages refer to files in other directories outside it. Symlinks don't work, so you'll have to copy files in the directory that serves as gh-pages.
If you use gh-pages as master, this problem won't occur.