Deploy WordPress with Git on SiteGround: A Step-by-Step Guide

I use SiteGround for most of my personal websites because it lets me host unlimited sites at no extra cost.

I prefer deploying code with git instead of SFTP: I make changes locally and, when ready, push them with git push production master.

SiteGround includes built-in git support, but it behaves a little differently than other hosts that accept direct git pushes. A helpful guide by 9seeds offered useful pointers when I first set this up.

Add a .gitignore file

By default, SiteGround places the entire wp-content directory under version control, which includes themes, plugins, and uploads. If you only want to version control specific themes or plugins, add a .gitignore file before creating the git repository on SiteGround.

I migrated a site to SiteGround and then clicked “Create git repository,” which resulted in a very large repo because it included about 2GB of uploads. Adding a .gitignore afterward and deleting the uploads directory did not remove them from the repository history. I solved this by deleting the repository, adding the .gitignore file to the site root, and creating a new repository.

I keep a sample .gitignore that you can adapt to include only the themes and plugins you want to track; upload this file to the top level of your WordPress install before creating the repo.

Create the repo on SiteGround

Log in to SiteGround, open cPanel, and launch the “SG-Git” tool (use the cPanel search to find it).

In the SG-Git interface you’ll see domains that are not yet under version control. Click the green “Create git repository” button next to the site you want to manage.

A popup will provide a “git clone” command and an SSH key. For basic workflow you only need the git clone command.

Copy the git clone command and run it locally where you keep your development sites. For example, I have a /wpdev directory on my machine; running the clone there creates a new folder named after the domain (for example /wpdev/yoursite.com). You can rename that folder if you prefer, for example mv yoursite.com yoursite.

Integrating GitHub

The local repository you cloned from SiteGround will have a remote named origin that points to SiteGround. I prefer using GitHub as the primary remote and naming the live SiteGround remote production. To switch this up:

  1. Rename the existing remote: git remote rename origin production
  2. Create a private repository on GitHub and copy the clone URL.
  3. Add GitHub as the new origin: git remote add origin

Note that private GitHub repositories require a paid account. As an alternative, BitBucket offers unlimited private repositories on free plans and works the same way for this setup.

Making code changes

When you want to push changes to GitHub, run: git push origin master. To deploy changes to the live SiteGround site, run: git push production master. For database synchronization I often use WP Migrate DB Pro to push and pull the database between environments.

Using git with SiteGround is straightforward once configured and avoids the repeated hassles of SFTP for code deployments. If you have questions or other SiteGround tips, I’m happy to help.