Using Wordpress with Git - which files should I ignore?
You can ignore almost everything with the following exceptions:
- wp-content/themes/my-theme (your theme and/or child theme)
- wp-content/plugins/my-custom-plugin. (any custom plugins you create)
Additionally, I have found two very good sources for gitignore files for WordPress. The first which is very straightforward is on gitignore.org (https://gitignore.org/gitignore.html#wordpress) and the second which is extremely surgical is by Sal Ferrarello and can be found here: https://salferrarello.com/wordpress-gitignore/
Just modify as required and of course, avoid the config.php. It has install specific info such as your database host & login which you may not want to expose to prying eyes.
Laravel's .env
file contains sensitive data just as WP's wp-config.php
so we don't usually push it into the repo.
As to how I use Git with WordPress:
- I exclude the
wp-config.php
file, the developer cloning the repo doesn't need it anyways: they can fill in the credentials themselves when working on the project on their local development environment. Another good reason to leave this file out is you don't want to expose your site's details (host, database name, username, password, salts, etc) to the world. - I exclude the
uploads
folder. The reason is that while developing we usually add dummy images to our posts and pages, images that won't be used at all when the site is finally ready for production so there's no reason to "pollute" the repo with these.
One of the things I love about Laravel is that database changes can also be tracked thanks to migrations. WordPress, on the other hand, doesn't have anything like that so you'll have to find a plugin (or some other mean) to keep your local database in sync with the staging one.
Update:
Since you updated your question to ask which files should be specifically excluded from the Git repo, I think the ones you posted from that .gitignore
file you found are good enough. I don't see the need to ignore the readme.txt
file though but that won't do any harm either.