Use Github for Hosting Files: Using GitHub Pages To Host Your Website

0

Use Github for Hosting Files: Using GitHub Pages To Host Your Website? Git, GitHub, and GitHub Pages are all very closely related. Imagine Git as the workflow to get things done and GitHub and GitHub Pages as places to store the work you finish. Projects that use Git are stored publicly in GitHub and GitHub Pages, so in a very generalized way, Git is what you do locally on your own computer and GitHub is the place where all this gets stored publicly on a serverUse Github for Hosting Files: Using GitHub Pages To Host Your Website? Here are some products that make up GitHub’s tech stack in addition to what’s mentioned in the excellent link PJ shared: Bonsai, BrowserStack, Cask Data Applicaiton Platform, Cowboy Web Server, DigiCert, Dyn DNS, Elasticsearch, Fastly, Git, Heroku, MySQL, New Relic, PagerDuty, Pusher, Ruby on Rails, and Xamarin Insights. Online project hosting using Git. Includes source-code browser, in-line editing, wikis, and ticketing. Free for public open-source code. GitHub provides two types of plans: free plans for open-source projects and paid plans offering unlimited private repositories. Both plans have the exact same features. They can have any number of public repositories, with unlimited collaborators. Paid accounts can create unlimited private repositories. Use Github for Hosting Files: Using GitHub Pages To Host Your Website

How to Host Files on Github: Use Github for Hosting Files 

Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Additionally, here’s a list of other software products that GitHub is using internally:

  • Marketing: Campaign Monitor, MailChimp, Mailgun, Mailtrap
  • Analytics: Crazy Egg, Gauges, Google Analytics, Mixpanel
  • HR: Bright Funds, Culture Amp, Hired, TheLions
  • Productivity: Blue Jeans Network, Flowdock, Google Apps for Work, OpenProject

For a complete list of software used by GitHub, check out: GitHub’s Stack | Siftery

Use Github for Hosting Files: Using GitHub Pages To Host Your Website
Use Github for Hosting Files: Using GitHub Pages To Host Your Website

It takes few easy steps to turn your Github into a file repository. You can upload files from the browser and you can add collaborators so they can also upload files to a common repository (similar to shared folders in Google Drive). The files are public so anyone can download them with a direct link. The one limitation is that the individual files cannot be larger than 25 MB each. There are no known bandwidth limits though.

Step 1: Go to github.com and sign-up for a free account, if you don’t have one. Choose the free plan as that’s all we need for hosting our files.

Use Github for Hosting Files: Using GitHub Pages To Host Your Website
Go to github.com and sign-up for a free account tutorial_github_signup

Step 2: Click the “New Repository” button, or go to github.com/new, to create a new repository for hosting your files. You can think of a repository as a folder on your computer.

Use Github for Hosting Files: Using GitHub Pages To Host Your Website
add new “New Repository github

Step 3: Give your repository a name and a description and click the Create button. It helps to have a description as it will help others discover your files on the web. You can have Private repositories too but that requires a monthly subscription.

Use Github for Hosting Files: Using GitHub Pages To Host Your Website
repo-create-name- Give your repository a name and a description github

Step 4: Your repository will initially be empty. click the Import Code button on the next screen to initialize the repository.
Step 5: Paste the URL https://github.com/name/files.git into the repository field and clickBegin Import to create your Github repository for hosting files.

Upload Files to Github: Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Your Github repository is now ready. Click the Upload Files files button and begin uploading files. You can drag one or more files from the desktop and then click Commit Changes to publish the files on the web. Github will accept any file as long as the size is within the 25 MB limit.

Github has a built-in previewer for PDF, text and image files (including animated GIFs) so anyone can view them without downloading the actual file. Else there’s a simple URL hack to get the raw (downloadable) version of any file hosted on Github.

 

Direct URLs for Github Files

After the file has been uploaded to Github, click the filename in the list and you’ll get the file’s URL in the browser’s address. Append ?raw=true to the URL and you get a downloadable / embeddable version.

Is it safe to Host Files in GitHub

Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Use Github for Hosting Files: Using GitHub Pages To Host Your Website
safe to Host Files in GitHub

The most attractive part is that, they claim no intellectual property of your files. If you check their Terms of Service, it will have something like this, “We claim no intellectual property rights over the material you provide to the Service. Your profile and materials uploaded remain yours.” And the news is that, Torvalds and other developers have adopted Git for developing their Linux core. This suggests that this platform has a very long life in the market, which should give you lot of assurance regards its reliability.

There are thousands of really cool and exciting repositories on GitHub, with new ones added every day. Some examples of popular software development projects that make their code available on GitHub include:

  • Twitter Bootstrap, an extremely popular front-end framework for mobile first websites, created by developers at Twitter.
  • HTML5 Boilerplate, a front-end template for quickly building websites,
  • The JavaScript Visualization Library D3
  • Ruby on Rails, the open-source web framework built on Ruby.

Usually, people just host the files that contain their code, so what you see on the end view is the actual code

How to use github to host website

Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Note: This post assumes that you have a GitHub account and some basic knowledge of the version control system Git.

Create GitHub Repository

Note: If you are not adding your website files to an existing repo make sure that you setup a new repo before continuing.

Now open up terminal (command prompt on Windows) and make sure that you have a copy of your GitHub repo on your computer. Once you got your local copy, move into the project folder using the cd command.

// Retrieve a copy of your GitHub repo.  
git clone https://github.com/user/repository.git
// Move into that directory.
cd repository

Note: Make sure that you change the clone URL to the URL of your GitHub repo. This can be found on the main project page.

Creating an Orphan Branch

Use Github for Hosting Files: Using GitHub Pages To Host Your Website
Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Now you need to create a new orphan branch within your repo that will hold all of your website files.

This new branch should be called gh-pages.

git checkout --orphan gh-pages

If you already had files in the master branch of your GitHub repo you now need to delete these from the new gh-pages branch. To do this you can use the following command:

git rm -rf .

Adding Website Files

Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Now that your repo has been properly setup it’s time to add all of the HTML, CSS and JavaScript files that make up your website. Once you have added these to your repo you need to commit the changes. To do this you can use the following command.

git commit -a -m "Adding pages"

Note: The -a flag is shorthand for git add .

Pushing Changes to GitHub

Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Okay so you’ve got all your files where they need to be. The only thing left to do now is to push the new gh-pages branch up to GitHub. You do this using the git push command.

git push origin gh-pages

That’s it! Your website should now be available at http://username.github.io/repository/.

Using a Custom Domain

Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Use Github for Hosting Files: Using GitHub Pages To Host Your Website
Use Github for Hosting Files: Using GitHub Pages To Host Your Website

The last thing I want to cover in this post is how you can use your own domain name with your new GitHub-hosted website.

First you will need to create a new file in your GitHub repo called CNAME that contains the domain name (or subdomain) that you wish to use. This file should be placed in the gh-pages branch if you are using project-pages (as we have been in this post). If you are using user-pages the file should be placed in the masterbranch.

Your CNAME file might look like the following:

domainname.com

Next you will need to update the DNS records for your domain name. This is usually done through a control panel provided by your domain registrar.

If you want to use a root domain (such as teamtreehouse.com) for your website you will need to setup a new A record that points to the IP address:

192.30.252.153 or 192.30.252.154

If you are using a subdomain (such as blog.teamtreehouse.com) it’s best to create a new CNAME record that points to your GitHub user subdomain (**username**.github.io). This is so that the DNS will be automatically adjusted if the servers IP address changes on GitHub.

Note: For information about the difference between CNAME and A records check out this video.


Is GITHUB free?
GitHub provides two types of plans: free plans for open-source projects and paid plans offering unlimited private repositories. Both plans have the exact same features. They can have any number of public repositories, with unlimited collaborators. Paid accounts can create unlimited private repositories.

Github Terminology : Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Repository : A repository is a folder inside which you are going to store                            every piece of your code
Fork : Copying someones repository into your account is called forking.
Upstream : The guy or organisation which owns the code that you forked.

1. What is Git ?

Version Control System ( Keep reading and this will make sense towards the end ) .
Lets say you have a project you want to work on.
Now you have 2 primary motives.
          (a)  To write some code
(b)  To take up the project as a team , meaning that more than  one                           people are going to be responsible for writing the code.

So suppose you write a “Hello World!” program and then your friend/other developer decides that it should say “Hello, I am awesome”
instead of the original “Hello World!”.

Even for this little piece of code, you will have a copy in your PC and your friend will have one in his PC.
Lets say you change the code, now at this point your friend wouldn’t know the changes you have made and vice versa.

This is where the Git magic comes.
    1. Git lets you save your code online.
    2. Git will allow all the developers of a project to see what changes the other one has made.
    3. It allows you to discuss issues in your code with other developers.
     And a lot more…

I think now you have a decent idea of what git is.

2. Getting Started

First, Signup on Github.
-> Next, Download git for you OS from this page Git – Downloads
-> Next you go and do this   Create A Repo · GitHub Help

So now you have created a repository Online, and you have installed git on your PC. Until now they are not linked to each other.

-> To do that follow the instructions under “setting up git” Set Up Git · GitHub Help

Setting Up is done !!

3. One step ahead

If you forked someones repository ( Forked , explained under terminology, scroll up ) then follow these instructions Fork A Repo · GitHub Help and then the commands below.

If you are the upstream yourself ,( ie. you are the guy who created the original repository ) then follow the instructions below

$ git clone <add the repository address here>
( Clones/copies everything from that repository to your local machine )
$ git add filename.extension
(this adds the file you want to change on the server)
$ git commit
(this commits your changes to the repository with an explanation message)
$ git push origin master
(this finally sends all your changes to the server. This is the final step of changing the code on your repository on the server)

You just started using github.  Use Github for Hosting Files: Using GitHub Pages To Host Your Website

Leave a Reply