I know this question has been asked a thousand times, but I’m really trying to work out how to get the best out of Git when working with WordPress.
I’ve scoured the web and read dozens of articles, all that seem to cover the topic briefly. Here’s a few of the most notable one’s I’ve read recently.
– Version Controlling WordPress
– Managing WordPress Theme Deployments with Git
– Manage your custom WordPress theme using git instead of FTP
Currently, my workflow looks like this.
- Install WordPress locally
- Develop Theme
- Export WordPress Databases from local server
- Import WordPress Database to remote server
- Upload WordPress files and theme via FTP
- Client makes changes
- Download WordPress files and theme via FTP and export WordPress Databases from remote server
- Replace files locally
- Make development changes
- Re-upload via FTP, export and import database to remote server
I realise Git can streamline this process. It seems the best way to do this is to have a .gitignore file that ignores certain directories that don’t need to be tracked, as well as having both a local and remote wp-config.php file.
But how do you handle the databases? Clients will usually make changes (posts/pages/plugins). Do I still need to export from the remote database and import back on my local server?
Can someone suggest the best workflow for me here? And walk me through the steps.
Also, I’d probably like to use Bitbucket as private repos with them are free, unlike GitHub.
Any help would be appreciated.
Thanks in advance!
I’m one of the developers of WP Migrate DB Pro, and would like to answer @Ennui’s question:
“Do you know if the db url replace script it runs takes into account serialized strings?”
Yes, it does handle serialized data. In fact, that is the primary reason I developed the free version of the plugin back in 2009. 🙂
Unfortunately I only have a reputation of 41, so couldn’t reply to @Ennui’s comment. Sorry for that.
I am borderline on voting to close this as “not constructive” as it seems to be the kind of thing that will solicit debate and opinion rather than answers. But…
That is not what my work flow looks like, and it makes my approach (and answer) different from most of the rest of the answers so far.
stable release.
I nearly always install.
that database edits will not be transferred to the production site.
development server.
the client) will clean the database on the staging server and upload
content.
site via the vanilla export tool and imported into the production
site.
with pretty standard tools. I will use Velvet Blues Update URLs to clean up the database if needed.
Basically, I keep the client away from my stuff as much as possible until we hand over the site.
Code moves one way– from local to either staging or production. It never moves the other way. That eliminates some of your steps and give me some peace of mind. I do not want to be blamed for the client’s tinkering in my code and I don’t want to import some hacked file, which is a non-zero possibility.
And the database only moves once, if at all, which greatly reduces the problem. So I guess I manage the “database moving” problem by reducing or removing the need to move the database. It also reduces database corruption issues that can arise and reduces the chances of importing a hack.
True, I do have to configure the production site– permalinks, menus, etc.– but that forces me to work on the production site so I consider it a kind of debugging. It helps me confirm that things work on the production site the way they should.
https://github.com/nathanielks/Wordpress-Capistrano-Deploy
I haven’t tried this myself (yet), but it claims to deploy everything — DB included.
There is also a tutorial to go with it:
Tutorial part 1
|
part 2
Take a look at the bedrock stack. It uses composer to manage the version of WordPress and third party plugins, and also includes capistrano for deploys, and vagrant / ansible for setting up servers including local virtual servers for development.
I recently did a lot of testing regarding this and here is the workflow I use, which does pretty much what you’re asking for:
I’m not familiar with the db migration tools but would be a great addition to this workflow.
Here are the full details on the workflow http://geekpad.ca/blog/post/maintainble-portable-wordpress-using-composer-wp-cli
Regarding the database “cloning”, I use WP Migrate DB Pro: http://deliciousbrains.com/wp-migrate-db-pro/
It’s a paid service, but doesn’t cost much, and easily allows you to pull or push your database from your dev to your live server and vice versa. It changes the URLs and everything else that needs changing on the way.