Momo
Momo

Reputation: 3810

Viewing changes to github pages on a specific branch

I currently have my github pages repository, b.github.io, which is forked from a.github.io. The a repository uses the master branch to publish the content of the website.

Now, I want to contribute to a via my repository, b. Because I have good faith in branch management, I wish to split my work on my fork into different branches: somebranch, another, etc.

Now, if I do changes to either of these branches, they will not reflect into my Github website (b.github.io shows the content of master, which is in sync with a.github.io). I'd need to see these changes to check if my changes work out before calling a Pull request.

How can I view the changes of the seperate branches? I tried things like b.github.io/tree/somebranch, without much success.

Upvotes: 12

Views: 4816

Answers (3)

VonC
VonC

Reputation: 1326784

I'd need to see these changes to check if my changes work out before calling a Pull request.

You should now (July 2020, 4 years later) be able to view your changes on your second repo (before doing a PR) from... any branch you want.
This is still in beta, but:

Build and deploy GitHub Pages from any branch (beta)

Repositories that use GitHub Pages can now build and deploy from any branch.

Publishing to the special gh-pages branch will still work the same as it always has, but you can now choose a different branch in your repository as the publishing source.

This functionality also removes the hardcoded dependency on user and organization pages having a master branch.

Sept. 2020: this is out of beta!

Upvotes: 2

David Jacquel
David Jacquel

Reputation: 52829

Github pages uses Jekyll to render pages.

So, you can :

  • install Jekyll locally,
  • make your preview on any branch,
  • merge in master when you're happy with your changes,
  • push to b.github.io
  • make your PR to a.github.io

Upvotes: 2

lucash
lucash

Reputation: 2062

First of all I think there is no way to just view another branch on github pages. However there might be options to view the site which would be shown if another branch were your master branch.


If the only point of the b repository is to test your changes, just stop to keep the two master branches in sync and put your changes to be pulled in the master branch to view it on b.github.io.

You can push any other branch to the master branch of b and then view it at b.github.io like this (assuming b is added as a remote to your local repository):

git push b somebranch:master

Please be aware that this will fail if the remote master contains commits which are not in you local branch. In that case you can enforce the push using the -f option. However be very careful doing this and make sure the remote does not contain any commits which will be lost doing so. To do that you could do something along with this:

First make sure to fetch all changes from the b remote and show the last commit of the master branch:

git fetch b
git show b/master

From that commit pick the commit hash and then check if it is contained in any other branches:

git branch -a --contains {hash}

This shows you all branches (remote or local) which contain that commit. As long as you are only pushing different local branches to b/master, this will always show the local branch you have pushed the last time.


If you can't mess with the master branch of the repository b, an alternative might be to create a separate repository for viewing your changes and create a project site as described here: https://pages.github.com/ However in that case you always need to push your changes to the branch gh-pages. To do so proceed as described above for the master branch.


I'm not sure why you need to watch your site via github pages. If your site is just static you could test it using a webserver (e.g. nginx or Apache) running on your local machine. If you are using Jekyll, github provides a documentation of how to run that yourself.

Upvotes: 0

Related Questions