Managing your Ghost Theme with git

On Ghost For Beginners, All About Ghost, and All Ghost Themes, David has created custom Ghost themes for each of the sites. Theses themes are kept in git repositories on GitHub and we have been manually copying themes changes up to their DigitalOcean Droplets with the command line scp. This has become annoying so we decided pull themes changes directly from GitHub with the git pull command.

First we needed to install git:

apt-get install git

Next we created an SSH key to allow us to authenticate with GitHub. You can use an existing SSH key but we would recommend creating a SSH key that is just used for interactions with GitHub. To create a new SSH key follow these steps from GitHub. In addition to creating the SSH key follow the steps to add your new SSH key to your GitHub account.

On your server running Ghost we need to make sure ssh-agent is running and stays up and running. To do this we modified /etc/bash.bashrc which gets executed when any user logs into our server.

This is what we added to /etc/bash.bashrc:

export NODE_ENV=production


function start_agent {
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add "$HOME/.ssh/abdb_deploy">/dev/null 2>&1;

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    #ps ${SSH_AGENT_PID} doesn't work under cywgin
    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {

Note that we specifically added a ssh-add to add our deploy SSH key once ssh-agent is started. You should modify this line to match the name of your SSH key:

/usr/bin/ssh-add "$HOME/.ssh/abdb_deploy">/dev/null 2>&1;

Now that we can authenticate to GitHub we can do a git clone of our theme.

cd /var/www/ghost/content/themes
git clone 

Then we restarted Ghost and selected the new theme in the settings. Now whenever David makes a theme change he can commit and push from his local workstation, log into our DigitalOcean Droplet and:

cd /var/www/ghost/content/themes/howtoinstallghost/
git pull
pm2 restart all


When starting ssh-agent if you receive the following message:

mkdtemp: private socket dir: Permission denied

You need to make sure that everybody has write access to /tmp which you can do with the following command:

sudo chmod a+w /tmp