Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you view a different branch of your GitHub Pages?

My master branch is accessible by {USERNAME}.github.io. Let's say I make a new branch named "mobile" and make some new commits on the web interface. How to do I view the new mobile branch, locally, without merging it into master?

like image 709
Taylor Kline Avatar asked Jun 17 '14 18:06

Taylor Kline


People also ask

How do I switch branches in GitHub?

You can use the git switch - command to undo any changes you make and return to your previous branch. If you instead want to keep your changes and continue from here, you can use git switch -c <new-branch-name> to create a new branch from this point.

Can I have multiple GitHub Pages on one?

Yes, it is possible to have multiple GitHub Pages sites within one account. Create another GitHub repository and push your site files to the gh-pages branch.


Video Answer


2 Answers

GitHub Pages are built on top of Jekyll, which you can also install and run locally. The short version is:

  1. Install Ruby
  2. Install Bundler
  3. Install the version of Jekyll that GitHub uses by creating a Gemfile that contains

    source 'https://rubygems.org'
    gem 'github-pages'
    

    and running bundle install

Once that is done you can run Jekyll locally in a way that matches GitHub's setup for Pages:

Running Jekyll

To run Jekyll in a way that matches the GitHub Pages build server, run Jekyll with Bundler. Use the command bundle exec jekyll serve in the root of your repository (after switching to the gh-pages branch for project repositories), and your site should be available at http://localhost:4000. For a full list of Jekyll commands, see the Jekyll documentation.

I believe you'll want to do this from your mobile branch.

like image 168
Chris Avatar answered Oct 19 '22 22:10

Chris


One option might be to fork your primary repo to a secondary one (call it beta.yourdomain.com) and then build there and test on the beta domain, before pull-requesting the final version back into your master repo.

TL;DR - don't use a branch, use a forked repo and a subdomain to preview the build :)

like image 29
Alex Morris Avatar answered Oct 19 '22 23:10

Alex Morris