How to host your website in github!

Hi there, Today I will show you two simple methods to host your website in github. It's very simple, easy and totally free.



First Method- As a github.io website

First you have to create a github account. There you have to give a username. That username will be used in your github.io website. For an example I have created my new github account as techmindlk.


Now create a new repository. Name of this repository should be your-github-username.github.io  .


Now create a new folder in your personal computer using the same name and add the files of your website.




 Now open up the Git Bash terminal in that folder.( To use Git, first of all you have to install it to your computer and setup it first. 

After that type following commands in your Git Bash terminal.


To initialize your folder as a git repository type git init .After that to commit new changes in your repository first type "git add  ."  and after that type "git commit -m "First commit" "and hit enter. 

Next step is very important. From this command we point out the remote repository on github to the local repository on your personal computer.
       git remote add origin https://github.com/username/username.github.io.git  
Add your username to the position where I have mentioned username in the URL.

As the last step you have to push your files to the remote(github) repository. For that type "git push -u origin master " and hit enter.

These commands will be shown in your github repository when you create a new one. So you can easily copy & paste those commands to your Git Bash terminal.

Now your remote repository will look like this.



Now go to a new tab in your file browser and search username.github.io. Then you will your website like this.



Second Method - Host in Github pages

In previous method you have only create a website with your username. But using github pages you can host any of your repository with different URLs.

Let's take an example. First create another repository and name it as "portfolio". Now create a local repository using that same name. Then add your files to it and push them to your remote repository as before.

Now create a new branch from master branch and name it as gh-pages.




Ok! Now go to the settings of the this repository. And scroll down. You will see something like this


Click on the link.



See! Now the url is different than the first method. So like this you can host multiple websites using your github account.

Find my repositories from here. 


So that's it. Hope you all learnt a new thing. Let's meet again with the next tutorial. Good Luck!

Thank you!

Kalpani Ranasinghe
email: kalpanibhagya.kb@gmail.com
Facebook icon Twitter icon LinkedIn icon Google Plus icon

Comments