What to include in .gitignore file for WordPress websites

When you want to add the GIT source control for your WordPress based website this is always the first question that comes into the mind – what to include in .gitignore file? Here’s a golden recipe:

A WordPress configuration file and its template file

Including these in a .gitignore file is a mandatory thing since these files contain access data (database server login information, salt keys, etc). In general you should not store in a repository anything that contains access data or sensitive information because of potential leakage. Also not to mention that these files contain environment-specific information.

Apache / PHP server configuration files

These are also environment-specific files which should be stored directly on the server.

Error log files

Error log files contain nothing but information about errors the site is experiencing and they TEND to grow in size.

Dynamic files and directories

These are all files and directories where we expect the content to chage. This includes cache files and directories, language file directory, upgrade directory, uploads directory, plugin data files and directories (e.g. EWWW Image Optimizer and WP CloudFlare Super Page Cache, Query Monitor link, Autoptimize 404 handler file, etc) and the list is not even complete (could change because of different setup of plugins). Essentially the first 5 should always be included.

Filesystem leftover files

Often automatically generated by either Macintosh or Windows operating systems. These are filesystem files which are not related to your project in any way and should not be included since they can also contain a sensitive information.

Summary

So now that we’ve reviewed every part of what to include, here’s a complete copy of the recommended .gitignore file for WordPress based websites:

#WordPress configuration file and its template file
wp-config.php
wp-config-sample.php

#Apache / PHP server configuration files
/.htaccess
.user.ini
php.ini

#Error log files
*.log
error_log

#Dynamic files and directories
/wp-content/cache/
/wp-content/*-cache.php
/wp-content/languages/
/wp-content/uploads/
/wp-content/upgrade/
/wp-content/ewww/
/wp-content/db.php
/wp-content/autoptimize_404_handler.php
/wp-content/wp-cloudflare-super-page-cache/

#Filesystem leftover files
.DS_Store
Thumbs.db
Leave a Comment on What to include in .gitignore file for WordPress websites
About the author
I'm a full-stack WordPress developer with a 10+ years of solid experience in the core web development languages, development processes / techniques, web security, Linux server management and with pretty good understanding about proper semantics, UX/UI, technical SEO, good design and basic knowledge of company leadership. On top of that - a distant 5+ years experience as a computer and electronics repair technician which often enables me to understand also how the things work at the hardware level.
Your feedback matters!…
I hope you found this article helpful. Feel free to add some comments - your feedback is very important to me, as it drives my motivation and helps me to improve the content.