Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Branches Beginning to Branch

Pavle Lucic
Pavle Lucic
10,801 Points

Wordpress and git

Does git support wordpress websites, by that I mean can it trace changes to the db?

2 Answers

Kevin Korte
Kevin Korte
28,148 Points

The short answer is two fold, the short answer is no, the long answer is yes.

Git won't track database changes normally, and that's not a WP thing, that's a every website with a database thing.

What you can do is before you commit, you an export a copy of your database, and save that file in the folder scope git has access to, and check that file in. That way at a different computer, or another use, when you pull, you'll get the most recent files and database file, which you than import into your database before beginning. That way you would have versions of the database in git.

This won't show specific changes to the database, just version points, but that is generally fine. You'd have to do the same for images, or possibly move far enough back in your folder structure when you run git init that you also get the images and plugins folder.

Pavle Lucic
Pavle Lucic
10,801 Points

so the database is the problem.

Kevin Korte
Kevin Korte
28,148 Points

As far as if you pull changes from a git repo, you don't get the database mirrored? Yes that would be what's going on.

caroline
caroline
6,974 Points

Hi Kevin - I've been wondering about how I'm going to manage this and your answer is really interesting. Would you mind just clarifying what you mean by "save that file in the folder scope git has access to, and check that file in." Do you just mean you save the db file in the directory with the git repository, then do a 'git commit' for that file?

Also, if you have any links to good online resources about this that would be really useful. I've had a look for stuff about WP, git, and workflow and I'm just getting confused!

Kevin Korte
Kevin Korte
28,148 Points

I don't have any useful reading on the material, and I haven't even actually done what I'm talking about, because most of my database info on a dev site I don't want on a production site, but what I meant was is that it would be logically to put the root of your git in your theme's root, not WP's root. But wherever your git root is at, within it's scope (i.e. if your git root is at your theme, do put your db file in WP's root, because git won't see it), you export your dev database as a .sql file, put that file into your project, and than commit it.

Later when you do a git pull, you get the .sql file in your git, which you can than grab and import into mysql on the production side. This would also give you revision control on your database export file.

You'll still have to clean up urls in the database, since the urls would be your localhost urls in a production environment, you'll have to do a find and replace with all urls.

There are plugins that help make this process much easier, I can't recommend any cause I haven't used one, but it's a very common problem. There might even be an all in one plugin that can help move a database correctly from dev to production.

caroline
caroline
6,974 Points

Thanks Kevin. That's really helpful. I'm new to git (and quite new to web dev in general), so at the moment I'm just thinking ahead about how these things might work; I haven't even tried version control on my local WP site yet. I'll have a go at what you suggest, and I suppose if I run into issues I'll deal with them as they come up. Thank you so much for taking the time to answer.