Hosting Hosting Features Spanish version

Support article

Deployment with Git: Publish Your Website from GitHub

Learn to automatically deploy your website from GitHub to your hosting: webhook, automatic pull and simple CI/CD best practices.

Published: 12/07/2026 Updated: 12/07/2026

Introduction

Making a change to your website, uploading it via FTP, checking it works… and repeating. It’s the classic workflow, but it’s slow and error-prone. There’s a much better alternative: automatic deployment with Git.

With this technique, every time you do a git push to GitHub, your hosting updates itself. No FTP, no manual steps, no oversights. In this article you’ll see how to configure it.

What Git deployment is

Git deployment consists of connecting your GitHub repository (or GitLab, Bitbucket…) with your hosting so that, when you upload changes to the repository, they’re automatically published on your website.

It works like this:

  1. You make changes on your computer.
  2. You do git push to GitHub.
  3. GitHub notifies your hosting via a webhook.
  4. Your hosting executes a git pull and updates.

[Imagen sugerida: diagram of the automatic Git deployment flow]

It’s like having a team that publishes your website for you, every time you make a change.

Advantages of automatic deployment

  • No FTP. You don’t upload files manually again.
  • Fast. The change is published in seconds.
  • Reproducible. What’s on GitHub is exactly what’s in production.
  • Easy rollback. If a change breaks something, you revert in Git and the previous version deploys.
  • Teamwork. Several developers can push and everything syncs.

Prerequisites

To configure automatic deployment you need:

  1. SSH access to your hosting.
  2. Git installed (most cPanel hosts have it).
  3. A GitHub repository (or GitLab, Bitbucket) with your website’s code.
  4. Your website already configured as a Git repository on hosting.

If you don’t have SSH access, at miHosting we can enable it on most plans. Open a ticket if you need it.

Method 1: Manual deployment with pull (simplest)

Before automatic, let’s see manual. It’s the starting point.

Configure the repository on hosting

Connect via SSH and make your web folder a clone of the repository:

cd public_html
git clone https://github.com/user/mywebsite.git .

The dot at the end is important: clones into the current folder, not a subfolder.

Publish changes manually

Each time you want to update your website, connect via SSH and do:

cd public_html
git pull origin main

Your website updates with the latest changes.

This method is manual, but already saves you FTP. Ideal for starting.

Method 2: Automatic deployment with webhook

Here’s where the magic happens: your hosting updates itself when you push.

Step 1: Create the deployment script

Create a PHP file on your hosting (for example deploy.php) that executes the pull:

<?php
// deploy.php
$secret = 'YOUR_SECRET_HERE';
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE'] ?? '';

if (!hash_equals('sha1=' . hash_hmac('sha1', file_get_contents('php://input'), $secret), $signature)) {
    http_response_code(403);
    exit('Forbidden');
}

$output = shell_exec('cd ' . __DIR__ . ' && git pull origin main 2>&1');
echo $output;

This script checks that the request really comes from GitHub (with a secret) and then executes the pull.

Step 2: Configure the webhook on GitHub

  1. Enter your repository on GitHub.

  2. Go to Settings → Webhooks → Add webhook.

  3. In Payload URL, put:

    https://yourdomain.com/deploy.php
  4. In Content type, choose application/json.

  5. In Secret, put the same secret you put in the PHP script.

  6. In Events, select Just the push event.

  7. Click Add webhook.

[Imagen sugerida: screenshot of webhook configuration on GitHub]

Step 3: Test the flow

  1. Make a change to your code locally.
  2. Do git commit and git push.
  3. Enter your website: the change should be published in seconds.

If it doesn’t update, check the webhook delivery log on GitHub (Settings → Webhooks → Recent Deliveries).

Security considerations

Automatic deployment has risks if misconfigured. Keep in mind:

  • Protect the deployment script. Use a secret (like in the example) so only GitHub can execute it.
  • Don’t upload sensitive data to the repository. wp-config.php, .env files and the like should be in .gitignore.
  • Limit what deploys. It doesn’t make sense to deploy the WordPress uploads folder, for example.
  • Always have a backup. If a deployment breaks something, you need to be able to roll back quickly.

What to do after each deployment

Depending on your website, after a deployment you may want to:

  • Clear the cache. If you use LiteSpeed Cache or WP Rocket, clear the cache after the pull.
  • Run database migrations. In advanced projects.
  • Install dependencies. If you use Composer or npm, run composer install or npm install.

You can add these commands to the deploy.php script so they run automatically.

Useful tips

  • Start with manual pull. Before automating, make sure pull works well.
  • Test on a branch first. Upload changes to a staging branch, test, then merge with main.
  • Have automatic backup. Even if you use Git, it’s worth having a complete hosting backup.
  • Don’t deploy at critical hours. If you have an online store, avoid deploying at peak hours.
  • Review webhook logs. If something doesn’t work, GitHub’s logs will tell you what happened.

Common problems

The webhook doesn’t execute

Check that the webhook URL is correct and accessible. Also verify that the secret matches between GitHub and the script.

Pull fails due to conflicts

If you’ve made changes directly on hosting (without going through Git), pull may fail. Solution: connect via SSH and resolve the conflict, or reset state with git reset --hard.

Changes aren’t visible on the website

It may be browser cache or hosting cache. Try incognito and clear LiteSpeed/WP Rocket cache.

PHP script can’t execute git

Some hosts restrict what commands PHP can execute. If that’s your case, you need an alternative method (deploy keys with SSH, or an external deployment service).

I have several domains on the same hosting

Each domain needs its own repository and its own webhook. Don’t mix code from different websites in the same repo.

Frequently asked questions

Do I need a VPS for automatic deployment?

No. On many hosts with cPanel and SSH access you can configure it. For larger projects, a VPS gives more flexibility.

Does it work with WordPress?

Yes, but with care. Exclude wp-config.php and uploads/ from the repository. Git is ideal for managing custom themes and plugins.

Can I use GitLab or Bitbucket instead of GitHub?

Yes, the process is similar. Webhooks exist on all platforms.

Is automatic deployment safe?

Yes, if you configure the secret well and don’t upload sensitive data to the repository.

Can I revert a deployment?

Yes. If you use Git, you do git revert or git reset to the previous version and it deploys automatically.

Publish your website like a professional

Automatic deployment with Git is one of the practices that most differentiates professional development from amateur. It eliminates FTP, reduces errors and lets you publish changes in seconds.

If you need help configuring automatic deployment on your miHosting hosting, open a ticket from your client panel. And if your project needs a more advanced deployment environment, our managed VPS give you the flexibility of your own server with support from real technicians.