gh-pages branch is used with github repos as a front page for the repository. It is used to display demos, documentations, a stylized readme, and more. Some difficulties arise when the gh-pages branch needs to reference or contain files that originate from the master branch.
Work flows
Different work flow suggestions exist (see here, and there). These suggestions work, but I find that syncing the gh-pages so it would contain the latest code from master to be a bad practice. The DRY principle should be imposed here- each file should either be on master or gh-pages branch. Not both, and not resorting to use gh-pages as the master branch.
A different approach
Create the gh-pages as an orphan branch (also Github's recommendation):
1 | git checkout --orphan gh-pages |
dealing with special files
-
files from master that need to be referenced from gh-pages. For example- A demo page for a js client side widget. The demo should reference the distribution .js files. The easiest way the achieve this is to keep the distribution files in master, while inside gh-pages, use a 3rd party CDN to reference them such as RawGit.
-
files that get generated in master branch, but belong to gh-pages. For example- documentation files that are auto generated by a tool that scans the source files. This is a bit more tricky:
1 | error: The following untracked working tree files would be overwritten by checkout: |
assuming the files are in a folder named documentation
, the way around this is:
1 | git add documentation |
using git checkout stash@{0}
is preferred here over git stash pop
, since the stash command will result in conflicts which you will need to resolve manually (note the stash command doesn't take --theirs
).