How to host a website on Github

Sri Harsha Tanamala
3 min readNov 30, 2020

We can host a website for free on Github pages. This can be used to host our personal website, blog, portfolio, project, etc. without spending much effort and a single rupee. Github Pages are incredibly fast when compared to WordPress and other CMSs.There is no database or back-end execution in Github pages. So the chances of getting hacked are nil.

First, we require a github account and terminal.

Log in to github account. Create a new repository. This where we keep our project data.

click on new and continue the process.

Add the repository name and description. If required add readme also where we can explain about our project. The repository name should be “username.github.io”.

The following commands will all be done in the terminal.

Enter into the project folder through the terminal. ex: cd drive name/name_of_project

Execute “git init” , it will initialize your project ready for the next step.

we need to add the origin and need to use the link given to you after you submitted your repository.

git remote add origin https://github.com/yourusername/my_project.git

add all the files that we want to upload. we can add them individually, but to make sure we have not missed anything.

git add --all

Include a commit message. Type whatever you want in the speech marks, but as it’s my first commit.

git commit -m "initial commit"

push project to the master branch

git push -u origin master

now we can see all the files in our repository of github account.

If we require any changes that need to be done then do it in the local machine and push into the github account by adding a comment every time.

Now because we named our repository username.github.io, it should automatically be published as our main Github pages site. Put https://username.github.io in the browser to check that you can see it.

If in case it doesn’t work, click on your repository and then click on Settings in the top right corner. If you scroll down, you will see a section for Github pages. Select master branch as the source and you should then see a message. “Your site is published at https://username.github.io

If we have purchased a domain we can custom domain name. To custom domain check here. Ensure you check the Enforce HTTPS. As it adds a layer of security and makes your site look more secure. Without this, people might be worried about visiting the site.

--

--