496

On http://github.com developer keep the HTML, CSS, JavaScript and images files of the project. How can I see the HTML output in browser?

For example this: https://github.com/necolas/css3-social-signin-buttons/blob/master/index.html

When I open this it doesn't show the rendered HTML of the code of author. It shows the page as a source code.

Is it possible to see it as rendered HTML directly? Otherwise I always need to download the whole ZIP just to see the result.

3

11 Answers 11

610

The most comfortable way to preview HTML files on GitHub is to go to https://htmlpreview.github.io/ or just prepend it to the original URL, i.e.: https://htmlpreview.github.io/?https://github.com/bartaz/impress.js/blob/master/index.html

23
112

If you don't want to download an archive you can use GitHub Pages to render this.

  1. Fork the repository to your account.
  2. Clone it locally on your machine
  3. Create a gh-pages branch (if one already exists, remove it and create a new one based off master).
  4. Push the branch back to GitHub.
  5. View the pages at http://username.github.io/repo`

In code:

git clone git@github.com:username/repo.git
cd repo
git branch gh-pages
# Might need to do this first: git branch -D gh-pages
git push -u origin gh-pages # Push the new branch back to github
Go to http://username.github.io/repo
5
  • I have forked a project now how i can copied it to github pages. Dec 9, 2011 at 14:56
  • 1
    Updated my answer with a process.
    – Ross
    Dec 9, 2011 at 15:38
  • 3
    It's well documented here help.github.com/articles/creating-project-pages-manually Feb 18, 2013 at 16:15
  • 2
    Why first create a master and clone it ("play it safe" in creating-project-pages-manually) ? Can one not checkout --orphan gh-pages only, push that, without messing with master at all ?
    – denis
    Mar 7, 2013 at 17:48
  • 1
    You can also select the branch to publish in your repository settings, in the first tab (Options) near the bottom. It default to gh_pahes if the branch exists, else None (disabled). You can select master or any other branch. Apr 17, 2020 at 15:53
69

🚩 Message from RawGit's creator and owner on https://rawgit.com:

RawGit has reached the end of its useful life October 8, 2018 RawGit is now in a sunset phase and will soon shut down. It's been a fun five years, but all things must end.

GitHub repositories that served content through RawGit within the last month will continue to be served until at least October of 2019. URLs for other repositories are no longer being served.

If you're currently using RawGit, please stop using it as soon as you can.

When I tried to use it, I got:

403 Forbidden

RawGit will soon shut down and is no longer serving new repos. >> Please visit https://rawgit.com for more details.

You can use RawGit:
https://rawgit.com/necolas/css3-social-signin-buttons/master/index.html

It works better (at the time of this writing) than http://htmlpreview.github.com/, serving files with proper Content-Type headers. Additionally, it also provides CDN URL for use in production.

8
  • 2
    I confirm that it works better than htmlpreview. At least, it's showing my WebGL animations. Apr 19, 2015 at 15:00
  • 1
    It works faster actually, and with Bokeh (e.g.), it shows some of the interactions (e.g. tooltips) that don't work with htmlpreview.
    – jadianes
    Sep 23, 2015 at 15:46
  • 2
    This is from the FAQ for rawgit: Can I use a rawgit.com development URL on a production website or in public example code? No. Only use rawgit.com URLs for low-traffic testing or for sharing temporary demos with a few people during development. Please use cdn.rawgit.com for anything that might result in heavy traffic or that people might copy and paste into their own code. ... There is more explanation available
    – BarryPye
    Nov 9, 2016 at 12:44
  • 12
    Can confirm: Rawgit will be shut down as of October 2019.
    – samcozmid
    Mar 19, 2019 at 2:11
  • 2
    raw.githack.com as an alternative for RawGit. More info: stackoverflow.com/questions/62740362/…
    – mkczyk
    Oct 11, 2020 at 10:31
45

It's really easy to do with github pages, it's just a bit weird the first time you do it. Sorta like the first time you had to juggle 3 kittens while learning to knit. (OK, it's not all that bad)

You need a gh-pages branch:

Basically github.com looks for a gh-pages branch of the repository. It will serve all HTML pages it finds in here as normal HTML directly to the browser.

How do I get this gh-pages branch?

Easy. Just create a branch of your github repo called gh-pages. Specify --orphan when you create this branch, as you don't actually want to merge this branch back into your github branch, you just want a branch that contains your HTML resources.

$ git checkout --orphan gh-pages

What about all the other gunk in my repo, how does that fit in to it?

Nah, you can just go ahead and delete it. And it's safe to do now, because you've been paying attention and created an orphan branch which can't be merged back into your main branch and remove all your code.

I've created the branch, now what?

You need to push this branch up to github.com, so that their automation can kick in and start hosting these pages for you.

git push -u origin gh-pages

But.. My HTML is still not being served!

It takes a few minutes for github to index these branches and fire up the required infrastructure to serve up the content. Up to 10 minutes according to github.

The steps layed out by github.com

https://help.github.com/articles/creating-project-pages-manually

3
  • 3
    Works great. As a git noob, I forgot to $ git commit -m 'init' in between your lines. Jun 22, 2016 at 10:57
  • 1
    What will the URL be? Aug 7, 2016 at 14:43
  • hmm ... not so sure this is much easier than juggling kittens ...
    – dreftymac
    Dec 5, 2019 at 20:25
21

I read all the comments and thought that GitHub made it too difficult for normal user to create GitHub pages until I visited GitHub theme Page where its clearly mentioned that there is a section of "GitHub Pages" under settings Page of the concerned repo where you can choose the option "use the master branch for GitHub Pages." and voilà!!...checkout that particular repo on https://username.github.io/reponame

screenshot to support my answer

1
  • 1
    This now appears to be a paid product only if you are using a private repo. It's available for public repos.
    – anakaine
    Mar 29, 2021 at 1:21
4

Also, if you use Tampermonkey, you can add a script that will add preview with http://htmlpreview.github.com/ button into actions menu beside 'raw', 'blame' and 'history' buttons.

Script like this one: https://gist.github.com/vanyakosmos/83ba165b288af32cf85e2cac8f02ce6d

2

I have found another way:

  1. Click on the "Raw" button if you haven't already
  2. Ctrl+A, Ctrl+C
  3. Open "Developer Tools" with F12
  4. In the "Inspector" right-click on the tag and choose "Edit HTML"
  5. Ctrl+A, Ctrl+V
  6. Ctr+Return

Tested on Firefox but it should work in other browsers too

2
  • 1
    Very good; a proper technical solution which solves the real problem without any monkey business of relying on external websites. This should be something in the File menu of your browser: "eval page text as HTML".
    – Kaz
    Apr 2, 2022 at 15:45
  • 1
    IMHO, it would be faster to save the raw html page anywhere and to open it with a browser (just press Downloaded files button). Jul 1, 2022 at 20:47
2

If you have configured GitHub Pages you can get your public url like as:

https://<username>.github.io/<repository>/index.html

where <username> & <repository> will be the placeholder for username & repo name respectively

So, the result will be like this: http://necolas.github.io/css3-social-signin-buttons/index.html

If it is an organization with GithubPages enabled in all the repositories it will be something like:

https://<org>.github.io/<repository>/
2
  • What if the repo is in an organisation? Mar 3, 2022 at 15:59
  • @alessandro308 it will be like https://<org>.github.io/<repository>/ i have updated the answer Dec 7, 2022 at 9:39
1

Two approaches (for public repositories) worked well for me: both VERY SIMPLE and ABLE TO RENDER COMPLEX HTML PAGES with links to local CSS files and local JAVASCRIPT/VUE files.

  • METHOD 1 - With GitHub pages

To set up, go to: https://github.com/YOUR_ACCT_NAME/YOUR_REPO_NAME/settings/pages (see screen shot below)

enter image description here

Example of my original HTML page on the repo: https://github.com/BrainAnnex/life123/blob/main/experiments/life_1D/diffusion/diffusion_1.htm

How it looks rendered: https://brainannex.github.io/life123/experiments/life_1D/diffusion/diffusion_1.htm Notice how all the styling, graphics and interactive controls are all good :)

  • METHOD 2 - With free service raw.githack.com

Go to https://raw.githack.com/ and enter the full URL of yourpage (including the "/blob" part); e.g. https://github.com/BrainAnnex/life123/blob/main/experiments/life_1D/diffusion/diffusion_1.htm

Then the site generates 2 links that work quite well :)

A good alternative if GitHub pages were to become unavailable!

0

This isn't a direct answer, but I think it is a pretty sweet alternative.

http://www.s3auth.com/

It allows you to host your pages behind basic auth. Great for things like api docs in your private github repo. just ad a s3 put as part of your api build.

1
  • 3
    Looks like a 3rd party service which has nothing common with git. Where is the instruction how to use it in context of this question?
    – Stalinko
    Mar 24, 2020 at 4:31
0

If you are using an enterprise Github, you might not want to have a public facing github pages. One thing that worked for us is to:

For a HTML file in: https://github.private-repo.com/team/project/blob/master/order.html

Following is the URL that opens in a browser and retrieves the latest file as HTML: https://github.private-repo.com/pages/team/project/order.html

1
  • If you're using Enterprise GitHub then I think you can create a private GitHub Page.
    – ChrisW
    yesterday

Not the answer you're looking for? Browse other questions tagged or ask your own question.