Coolest Guides on the Planet

coolest guides on the planet

Coolest Guides On The Planet

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

Git and WordPress workflow for Local Dev on OSX to webserver

September 23, 2014 4 Comments

gir-workflow-wordpressThis guide shows a Git and WordPress workflow and demonstrates  version control using Git from a local development environment on OSX to a live production webserver which is a cPanel server running on CentOS.

CentOS cPanel comes with Git and you can do an easy install for OSX.

Set up SSH (no passwords)

A key requisite for this is that you have SSH access to your website which in some shared hosting instances can be limited. The biggest initial hurdle in getting the workflow going is to have passwordless SSH connection by transferring your locally generated public key into the authorised file of the remote server, once this is done and the connection works you are good to go.

In this guide just a regular WordPress theme directory named mytheme inside the webroot; /public_html/wp_content/themes/mythemename is going to be the example. This can be extended to the whole webroot, or any particular directory you want under version control.

Remote Server – Set Up Git Repo

First thing is to set up the server repo, but do it outside of the webroot public_html one level above in the user home. This will contain the version control data and later we will push the actual source files to our WordPress theme directory which will be known as the working directory. So SSH into your server and switch to home…

ssh [email protected]

If SSH is on a non-standard port:

ssh [email protected] -p2000
cd

Make a directory which will store our version control data and initialise it with a -bare option which will have no working directory. This is the way this needs to work and we will push the actual files to our working directory destination when we use the Git hooks.

mkdir wptheme.git
cd wptheme.git
git --bare init

This will be eventually be our master branch, you should be left with output like so

Initialized empty Git repository in /home/username/wptheme.git/

Local Dev Set Up Git Repo

Now lets set up a local Git repo and add the server repo as our remote. In this local example, the directory will be a local development site in WordPress which already has files already in it.

cd ~/Sites/wp2/public_html/wp_content/themes/mythemename
git init

Add all the files to be tracked (or only the ones you want), the period will add all files or else use the filenames themselves to add instead of the period:

git add .

 

And commit all the files

git commit -m "first commit"

Check the status and we should have a clean directory

git status
# On branch master
 nothing to commit, working directory clean

Add the Remote to the Local Repo

Still on the local environment, time to add the remote repo.

The naming might sound non-intuitive, setting up origin but it is more of a destination. Our local repo is master and our remote will be origin/master

git remote add origin ssh://[email protected]/home/username/wptheme.git

Or non-standard port

git remote add origin ssh://[email protected]:2000/home/username/wptheme.git

I found that for cPanel/CentOS when creating the remote you need to prefix the address with the ssh:// protocol.

Push our files and version control data up

git push origin master

You can check the remote URL by running

git remote show origin

Pushing the Server Repo to our Working Directory with Git Hooks

SSH back into your server  and make the actual working directory

mkdir wptheme ~/public_html/wp-content/themes/

Move to your server repo and change directory into the hooks directory

cd ~/wptheme.git/hooks

Make a new post-receive hook this hook will action once a remote repo has pushed to it, in other words once our local repo has pushed data to it it will execute the action inside – which is to move our latest tracked files to their destination.

nano post-receive

Add

#!/bin/sh
git --work-tree=/home/username/public_html/wp-content/themes/wptheme  --git-dir=/home/username/wptheme.git checkout -f

So here we are declaring the actual working directory and where the data is coming from. Save the file and make it executable

chmod +x post-receive

Test back on your Local Repo

First set the remote as the upstream master

git push --set-upstream origin master

Make a change to the WordPress theme and commit it

git commit -am "first edit"

Then push it to the remote server

git push

You should see along the lines of

To ssh://[email protected]/home/username/wptheme.git
   88003b9..600c2ef  master -> master

Check your working directory on the remote server and you should see your WordPress Theme.
Now all changes made locally will be pushed and tracked from local to remote.

Doing the whole webroot

You can use exactly the same technique and apply it to the whole webroot public_html directory and push all changes from local to production. The only thing that you may not want to push is the wp-config.php file especially if you are using simple passwords when on a dev environment like Vagrant VVV, for this you can either just place the legit remote wp-config.php file one directory above the webroot and add the local wp-config.php to the .gitignore file.

 

Ref.

Cats: Hosting, Imaging, macOS, WebDev, WebRoot, WordPress Tags: git

Tags

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!

Discuss

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls
Get DesktopServer

Lynda

Lynda.com Online Training Videos

TreeHouse

smlinks

Learn WordPress
osx-modify-shell-path

How to Add to the Shell Path in macOS Big Sur and Catalina using Terminal

October 19, 2019

virtual-hosts osx 10.10 yosemite

Set up Virtual Hosts on macOS Catalina 10.15 in Apache

October 19, 2019

Installing Homebrew on macOS Catalina 10.15, Package Manager for Linux Apps

October 18, 2019

Where is the bash shell in macos Catalina?

October 12, 2019

Refine your search

  • All
  • Modules
  • Themes
  • Documentation
  • Forums & Issues
  • Groups

RSS ars technica

  • Google hits back after Apple exec says AI is hurting search
  • Apple: “Hundreds of millions to billions” lost without App Store commissions
  • Matter update may finally take the tedium out of setting up your smart home
  • Cue: Apple will add AI search in mobile Safari, challenging Google
  • Apps like Kindle are already taking advantage of court-mandated iOS App Store changes

RSS mac surfer

  • Tot is new text editor for Mac, iPhone, and iPad focused on constraints and ease of use
  • TiPbITS: Google Drive Sorting Can Hide New Documents
  • How to take a screenshot on a MacBook Pro
  • How To Create Simple Animation With Mac Keynote
  • Last Week on My Mac: Virus pandemics

Donate

Copyright © 2025· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2025 · gee on Genesis Framework · WordPress · Log in