If you have a small blog or series on blogs on a shared hosting environment and and want to take advantage of GIT but still want to let your hosting provider keep your WordPress up to date, you can easily setup GIT repos and deployment to make your life easier.
Shared hosting services are great for a small site or if you have a bunch of small sites where you can setup different projects and not have to worry about the server environment or keeping WordPress or Drupal up to date. Hosting providers like Dreamhost, Bluehost, HostGator, SiteGround etc. are a great solution for some because they provide the hosting and upkeep of the WordPress install and you are free to add themes and plugins and do custom development on top. Most of these providers will automatically update the core WordPress on a regular basis. For business and enterprise class WordPress hosting I prefer Pantheon.
Initializing git in your theme and in your plugins folder.
I’m going to assume that you have a local development environment setup. Whether that is something like MAMP or LANDO or even APACHE, MySQL, and PHP setup through BREW like I do. First you’ll want to initialize GIT in your theme folder and in your Plugins folder. I do these separately so it’s cleaner for me and I can have separate GIT repos for separate themes that are installed if I want. You could easily initialize your GIT in the wp-content folder and gitignore other folders like the uploads and this would work the same.
In the theme or plugins folder in terminal use:
Once these are initialized as GIT repos we will hook them up to a GIT hosting service like github, gitlab, or bitbucket. Login to your GIT hosting service and create a fresh repos with a corresponding name. Then copy the repos URL and assign it as the remote endpoint to your local GIT instance.
git remote add origin [email protected]:USERNAME/NAMEOFREPOS.git
You can check this by typing:
git remote --v
Add your local files for your initial commit.
git add -A
Then push your file up to your GIT hosting provider.
You can do any of these GIT commands from the command line or you can use a GIT App. I like Sublime Merge, but mostly use the command line for these specific actions.
Setup a deployment service
You can easily just setup GIT on your hosting environment using the same git init and git remote add on your hosting provider once you’ve SSHed into your server. Once that is setup your can use git pull to pull down changes you’ve made.
I personally like to use a deployment service (I use DeployHQ) to automatically deploy changes to my site once a commit is pushed to a given branch in my repos. There are internal services for Bitbucket and Github that can do the same thing and are often free with your GIT hosting provider but I like the simplicity of setup and usage at DeployHQ. There are also other services like Bamboo, Team City by Jetbrains, CircleCI, Octopus Deploy and many others that provide the same service for roughly the same price.