Developing Themes Across Machines w/ Git

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.

1 Like

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

2 Likes

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

@ErikAGriffin I also prefer to create the repo at the root of the project as I do with all other frameworks, static sites or non web projects in general so changing it for just theme development just doesn’t feel right. Thanks for sharing :wink:

In this case the root of your project is your theme directory, after all it’s the theme that you are creating and sharing rather than the entirety of your local Ghost install :smile: Each theme is its own project.

Good point although I think it’s really relative to the developer and or just personal preference. I have one local install and work on multiple themes from that one install. For me personally the only reason I would break it up into two separate installs is if I did in fact need to share that repository with another dev or the owner for some reason but that will almost never happen for me.

Again just wanted to say thank you to Erik for being nice enough to share.