Auto Deployment Of Website from a Git Repository

If you are searching for Auto Deployment of Website from a Git Repository. You’ve come to the right place. In this article, we are going to discuss how can you deploy your website from a Git Repository like GitHub or Bitbucket.

Note: I am using Hostinger hosting on this example and a GitHub account.

I. Create a Github or a Bitbucket Account

First of all, you need to create a repository account, you can create from either Github or BitBucket account. Once done, open your repository and take note of your repository URL. Here is a sample GitHub repository URL. See the image below.

Note: We are going to use SSH for this example.

 An SSH key is an alternate way to identify yourself that doesn’t require you to enter you username and password every time
Github SSh URL

II. Setup Git on your Shared Hosting » Hostinger.com

Now, open your hosting dashboard which in my case it’s called Hostinger HPanel. Scroll down to the advanced section and open Git. See the image below.

Hostinger Hpanel dashboard

Configure Git by filing the details needed. Input the URL of your repository and indicate the Git branch that you want to deploy on this website. Then click on the Create button.

Git repository setup

You will see the created repository on the Tab shown below.

Git Repository

After that click the Auto Deployment button, You will be prompted with this option.

WebHook URL

Take note of the Webhook URL. We will use the webhook to automate the deployment of the changes made on the GitHub Repository.

What is WebHooks?

Webhooks provide a way for notifications to be delivered to an external web server whenever certain actions occur on a repository or organization.

III. Register Hostinger SSH Key on Github

Since we are using an SSH URL from the GitHub repository, we need to register the SSH Key of our shared hosting to be able to access the repository.

  1. Going back to the Hostinger HPanel, you will see this option. This is the SSH key that we need to register on our repository account.
Auto Deployment Of Website from a Git Repository

2. Navigate to your GitHub settings.

Auto Deployment Of Website from a Git Repository

3. Select SSH and GPG keys and add New SSH Key.

Auto Deployment Of Website from a Git Repository

4. Paste the SSH key that you copied from your Hosting account and Assign a title.

Auto Deployment Of Website from a Git Repository

IV. Setup GitHub Webhook

Now, let’s set up the WebHook on GitHub. If you remember you copied the webhook URL from Hostinger HPanel navigate back to your GitHub Repository then go to the Repository settings then choose the WebHook tab.

Auto Deployment Of Website from a Git Repository

Webhook settings:

  • Paylod URL » Webhook URL from Hostinger Hpanel
  • Content type » Content format
  • Events » Triger of the webhook. In this case I choose Just the Push event. Every time I push a changes on this repository this will also push or apply the changes on Hostinger.

That’s all folks. Deployment Automation is now complete.

Summary

In this article, we have learned how Auto Deployment Of Website from a Git Repository. And that Automating the deployment on shared hosting is easy. And can be done without a deep knowledge of the technical aspect. Hopefully, this article will help you automate your own website deployment on your current project.

KEEP CODING!!

Visit the Blog page for more free tutorials.

Start a website with Hostinger. Follow this link.