Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Last active June 23, 2021 17:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save waynegraham/64a3062368d97c5a3502ecdc7bf5e462 to your computer and use it in GitHub Desktop.
Save waynegraham/64a3062368d97c5a3502ecdc7bf5e462 to your computer and use it in GitHub Desktop.
Deploy wordpress theme via git

Deploying WordPress Theme via Git

I needed to deploy a child theme to a server for folks to check out the development. I went with a git remote to get the good stuff from git to quickly recover if (when) I break something.

Server Setup

On the server, I created a new directory:

$ sudo mkdir -p /var/repos/theme_name.git
$ cd /var/repos/theme_name.git
$ sudo git --bare init

Then created a post-receive hook (`/var/repos/theme_name.git/hooks/post-receive):

#!/bin/sh
GIT_WORK_TREE=/var/www/wordpress.clir.org/wp-content/themes/theme_name git checkout -f

Don't forget to make it executable:

$ sudo chmod +x /var/repos/theme_name.git/hooks/post-receive

Probably good to change the permissions on it too:

$ sudo chown -R `whoami` /var/repos/theme_name.git/

I'm already in the group that can write to /var/www/wordpress/wp-content/themes/theme_name, but you may also need to check those permissions.

Deployment

On your local machine, you'll need to set up a new remote.

$ cd path/to/project
$ git remote add myserver ssh://username@server/var/repos/theme_name.git
$ git push myserver +main:refs/heads/main

After this initial setup, you can push "normally:"

$ git push myserver

winning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment