I am looking at using git to manage version control for a WordPress project.
I typically have a local version, a development version on a web server that the client can access and test on and then a live version.
I will usually develop locally then push my changes to a repo on the server and then SSH into the dev folder on the server and pull from the repo. When I want to publish the changes on the live site I SSH into the live folder on the web server and pull from the repo.
Here is my dilemma.
I want the media added to the local version through the WordPress admin (image uploads etc) to be ignored but I want media added to the Dev version to be tracked so when I pull to the live site the media files from the dev site are pulled.
Any thoughts on the best way to make something like this work?
There may be better solutions to this, but these two options have worked fine for me in similar situations. Let’s assume that the branch you work on locally is called
master
and in all your repositories the remoteorigin
refers to the bare repository that you push to.If all your media fall neatly into one directory, you can have a separate repository that tracks the media and add that as a submodule to the dev and live repositories. In your local copy, you should either:
master
branch.git/info/exclude
Even if your media are in various directories you could still use this method, but managing submodules is a bit of a pain, and gets rapidly more irritating if you have lots of them.
Alternatively, you can keep your dev and live repositories on a different branch, say called
with-media
, which is always the same asmaster
but with commits that add the media at the end of the history. You can maintain this situation withgit rebase
. For example, if you’ve just made some changes locally that you want to push, you would do:Now suppose you upload some files to the dev repository, and want to commit them:
Now to update your live repository, you can just do:
To set up those branches in the first place, you would do:
As one last note, suppose you make some changes in the dev repository that aren’t just adding media, and you want those code changes in your
master
branch. Then (before you push anything!) you need to reorder the history withgit rebase -i origin/master
.In an ideal world you won’t need to do those last steps often, but in practice it’s good to know how to do that 🙂