Developing Themes Across Machines w/ Git


#1

Hello everyone,

I was editing a theme I had downloaded and was using Git to track changes. Normally, it is quite easy to use Git and a remote repository to duplicate development across machines, but without checking in the entire ghost installation into the repository I had extreme difficulties getting cross-machine development.

In the end, I have found a solution that works and wanted to share it with anyone that might be having the same issues. The basic gist of it is that for each development machine you use the ghost-cli to install a fresh local ghost installation, and using .gitignore only track the files within your theme folder.

So, to develop on a new machine you would:

  1. Create a new folder
  2. Use the ghost-cli to install a new local ghost
  3. Init .git
  4. Add your remote repository
  5. Pull in your changes
  6. Start ghost

Here is the .gitignore file I’ve used to allow this:

/*
!content/
content/*
!content/themes/
!content/themes/*
!content/themes/**/*
!.gitignore
.DS_Store
node_modules
bower_components
content/themes/casper
content/themes/**/assets/built

Note if you’ve already been using git with a theme and have checked in files related to the ghost installation that is giving you an error when you try to pull the repository to a separate machine… you may need to just rip out the theme folder into a fresh Ghost Installation with that .gitignore file in place. For my own project I was unable to retroactively fix the Ghost installation, even with git rm --cached everything in the repository except the theme folder.


#2

What’s your reasoning for commiting the Ghost code to git (i.e. the versions folder)? Could you not use content/themes/superawesometheme as the entrypoint to the git repo?

That way setup would be along the lines of

ghost install local
cd content/themes
git clone https://github.com/tryghost/casper casper-git

On every machine


#3

Ahh yes, that is perhaps an even better solution. I’m so used to initializing git at the root of a project I never thought of moving further down the tree.

Note that the .gitignore I provided also ignores the /versions directory, in fact ignores everything but theme folders