git branch: gh-pages
GitGit BranchGithub PagesGit Problem Overview
I have a repo on GitHub. Recently I have discovered GitHub's pages and I want to use them.
I would like to create this new branch and then, when I need to, either commit on master
branch or on gh-pages
branch.
How can I do this? Do I have to create another folder inside my repo?
Git Solutions
Solution 1 - Git
More recent versions of git have an alternative to the git symbolic-ref
method that Chandru explained. This avoids having to use the lower level commands.
git checkout --orphan gh-pages
git rm -rf .
Solution 2 - Git
You might find this tutorial useful:
To me this approach seems simpler then doing a git checkout gh-pages
each time you want to edit your gh-pages content. Let me know what you think ^_^
Edit: I updated the tutorial link - thanks @Cawas. The old tutorial (not recommended) was https://gist.github.com/825950
Solution 3 - Git
On your local clone do,
git symbolic-ref HEAD refs/heads/gh-pages
rm .git/index
git clean -fdx
Then, git checkout gh-pages
and write your pages. git push origin gh-pages
when you're ready to publish the pages.
Solution 4 - Git
There's yet another solution to your problem: Forget about gh-pages
and branching; Put your static files that are supposed to be served inside /docs
directory and then go to your project settings and tell github to serve /docs
content.
For more information take a look at this
Solution 5 - Git
Publish a static site like this:
git subtree push --prefix www origin gh-pages
Where www
is the doc root directory in which your static files are.
Your static site is now live at:
https://[user_name].github.io/[repo_name]/
Solution 6 - Git
> Creating Project Pages manually > > Adding a new set of Pages for a project manually is a straightforward > process if you're used to using command-line git.
https://help.github.com/articles/creating-project-pages-manually
Solution 7 - Git
Are your gh-pages and master branch having EXACTLY the same folder structure? If this is the case why do you even want to have two branches? just maintain one gh-pages branch! but if for whatever reason you want to have both branches that are constantly synced then your best bet is to use git rebase
. See here:
http://lea.verou.me/2011/10/easily-keep-gh-pages-in-sync-with-master/
You can also cherry pick only the files you need from master and push them onto gh-pages using a special use case of git checkout
. See here:
http://oli.jp/2011/github-pages-workflow/#gh-pages-workflow
http://nicolasgallagher.com/git-checkout-specific-files-from-another-branch/
Having had to tackle with the same problem I've come to find that gh-pages will usually end up having a different code base than master. In other words, gh-pages should only include the content of the dist/build/publish folder of your project whereas master will include your config files, unminified scripts and styles etc.
My suggestion would be to create gh-pages as an --orphan
branch and only include the publication-ready material in it. You would have to clone from your master in a different local directory, use git checkout --orphan gh-pages
to create gh-pages and then delete all the unnecessary files using git rm -rf .
. From there you can go on and push to gh-pages after having added your publish-only files.
Refer to Github docs for more info:
https://help.github.com/articles/creating-project-pages-manually/
Good luck
Solution 8 - Git
The typical way is to switch branches: git checkout master
if you want to work on master and git checkout gh-pages
if you want to work on gh-pages
.
Starting with git 2.5, you can have both branches checked out at the same time (in different directories). See https://github.com/blog/2042-git-2-5-including-multiple-worktrees-and-triangular-workflows. Setup via git worktree add -b gh-pages ../gh-pages origin/gh-pages
.
Bonus: If the content of a subdirectory of your master
checkout is the content of gh-pages
, use the script provided at https://github.com/X1011/git-directory-deploy.
Solution 9 - Git
I use this
git push origin `git subtree split --prefix build`:$DEPLOY --force
You can see working version https://github.com/rofrol/closeyoureyesnow/blob/master/build_and_deploy.sh