How to Use Github for Hosting Files

Github is a web-based Git repository hosting service. They provide the service for programmers to create repository in Github. We can also use Github for hosting files and small scale websites. In addition to the source control,
Github provides other features like

  • Issue Tracking
  • Pull, Commits Code with comments
  • Commit history tracking
  • Email notification
  • Graphs: pulse, contributors, commits, code frequency, punch card, network, members.
  • Wikis

There are many other things which can be done in the Github apart from the above-mentioned things. It seems like most of the features are for developers, but it can be used for many more things like you could use Github as CDN for your website by hosting all the CSS, JS and images files in Github. Let’s see in detail on how to host these files in Github.

How to Use Github for Hosting Files

Using simple steps we can turn Github repository into file hosting repository. Github has a web-based interface where we can use it to upload the files from the browser and add the collaborators so that they will have the option to upload the files to the repository. You can also give them the read, write access if they are contributors.

The repository will be public so that anyone would be able to access and download the files with a direct link. However, there is one limitation where you would not be able to upload any files above 25mb.

Step 1: You would require Github account, Go to http://github.com and sign-up for a free account if you don’t have one. You could select the free account option in the signup page to host the files on Github.

Step 2: Once the registration is completed, login to Github and then Click “New Repository” (Plus Mark on Top or New Repository Button on the Right-hand side) to create a new repository. Alternatively, you can visit https://github.com/new to create a new repo.

How to Use Github for Hosting Files

Step 3: Provide the repository with a name and then add a suitable description to it. Since you are using free account all the files hosted will be by default public and anyone would be able to view the files. You can make repositories private by paying a monthly subscription. Once you create the repository then you will be able to deploy any file and folder into it easily. If you need a standard Readme and License file then click on the checkbox Initialize this repository with a README.

Step 4: The repository you have created will be empty, you can create a sample README, LICENSE files as suggested by the Github to get the upload button. If you are not able to do that just click on the Import Code button in the Github and follow the next step to Setup your repository.

Step 5: Paste the URL https://github.com/catchsrinivas/filehosting.git into the repository field and click Begin Import to create your Github repository for hosting files.

Host file in Github Import Code

Upload files to Github Repository

If you have completed all the above steps then your Github repository is now ready to use as file hosting service. Click on the upload button or drag and drop the files into the area shown below to start uploading files into the repository.

Once you have uploaded all your required files click on commit to publishing the files on the web. Until you commit the changes you will not be able to see the changes. You can upload any file format to the Github repository the only restriction is file size should not be greater than 25mb in size.

How to get the Direct URL of the file in Github

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 of the file.

For Eg: There is a sample image(html.png) hosted in the test repository.Refer below screenshot for details. Now to download or embed this image we can give the URL as https://github.com/catchsrinivas/filehosting/blob/master/html.png?raw=true. We can embed this image in the HTML image src also.

Upload files Github

We can use Github as a CDN for any website by uploading all the CSS, Images, JS and PDF files inside the repository. Since this will be a public repository anyone would be able to read the JS and CSS. Hence, it’s best recommended to host only the image files in the Github if you are using it as a file hosting service.

 

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge