Updating a theme via git?

Hey folks, I’m wondering if it’s possible to use git to somehow make updates to my templates on my servers. I’d make the changes locally, commit it to git, and have my blog(s) update automatically on a cron job or something like that.

Am I making the process of changing my templates too convoluted? Should I just be uploading a new template every time I make changes and be done with it?

You mean like GitHub Actions?

2 Likes

I suppose I mean exactly that! Sorry. Very new to source control, systems administration. Learning a lot. Appreciate the snap response, Allan!

2 Likes

It works perfectly :slight_smile:

1 Like

Maybe you can help me out here, Andy! I followed the instructions on Github as linked by Stromfeldt above.

  • I made a new custom integration in Ghost.
  • On GitHub I made two new secrets in the repository named GHOST_ADMIN_API_URL and GHOST_ADMIN_API_KEY each containing the respective text from their entries on Ghost.
  • Created the .github/workflows/deploy-theme.yml sample as provided in the link, ensured it was committed on Github.com before proceeding.
  • I ran git clone <repo URL> in /var/www/ghost/content/themes and noted the directory existed now, and all the content is the same as it appears on Github.
    • The repository and Ghost site are Private for whatever that might be worth. During the git clone I provided my Github login & password.
  • The theme appeared in working order upon activation.
  • I committed a small visual change to Github, confirmed it on the web, but my theme is not updating.

I’m brand new to using git, so my thought here I’m missing something on the server-side to ensure the workflow is run?

Apologies if it’s just something small. Appreciate any help that can be offered!

GitHub Actions uses the Ghost API, not git, to push your changes to your site.

The reason this is better than using git is, Ghost’s API knows how to refresh the internals of your site so that your theme changes are all accurately reflected.

So this part of your work:

I ran git clone <repo URL> in /var/www/ghost/content/themes and noted the directory existed now, and all the content is the same as it appears on Github.

Was totally unnecessary. If you used this kind of git workflow, then every time you push a change to GitHub you’d then need to login to your server, go to this folder, run git pull and then restart Ghost. That’s a lot of steps.

Instead, what you need to do is push your changes to the master branch and then look at the “Actions” tab in GitHub to see if the build ran successfully.

If it did not run successfully, you will need to troubleshoot the errors in your Action first.

If/once it has run successfully, login to Ghost Admin and look at the theme list. The GitHub Action may have pushed your theme with a new name. If it did, you’ll need to activate that theme.

Once you’ve got that working successfully once, push a second change. This time the changes should be picked up without any additional work from you.

1 Like

Like Hannah mentionned, this is wrong " I ran git clone <repo URL> in /var/www/ghost/content/themes and noted the directory"

You are basically bypassing the whole point of using the API via the github actions :-p

1 Like

Well, I learned quite a bit about git! Thanks again folks. What a tremendous support structure here!