WordPress .gitignore

Updated May 2016. I wrote the original version of this in 2014 and have since change how I work, thus the update. Unfortunately there is no *right* answer.

Wondering how git fits into your WordPress dev workflow? Here’s a great little file to help you get started – WordPress gitignore. Don’t know what a gitignore file is for? Read up on the gitignore file on the git manual.

The contents of your .gitignore file will vary depending on your style of versioning your work. Some devs keep their entire WordPress sites under version control… including WordPress core and plugins/themes from the .org repo. Others only store custom plugins and themes while ignoring any code that’s not custom. I currently manage code/workflow in all these ways as it varies by project and requirements.

Basic WordPress .gitignore

However in any case, you should ALWAYS ignore the wp-config.php file and the file uploads. You shouldn’t store wp-config.php in git because it is generally unique to the environment it is in (dev, test prod) and it potentially exposes your database username and password. The file uploads (wp-content/uploads) directory should be ignore because it should be handle like content in a database. You don’t wan to store file uploads in version control for the same reason you don’t want to keep your database rows in version control. File uploads should be treated the same way and synchronized with a tool for different environments.

wp-config.php
wp-content/uploads

Other WordPress .gitignore Considerations

There are many other types of files you don’t want to clutter up your nice clean repo. There are many type of files found in the wp-content folder that you want to ignore. In most cases it’s easier to tell git what to look for (ie themes and plugins) than it is to list all the things to explicitly ignore. For instance, one will often find backups and cache stored in wp-content. These things can easily be generated and are often environment specific. These are others to often ignore…

wp-content/advanced-cache.php
wp-content/backup-db/
wp-content/backups/
wp-content/cache/
wp-content/upgrade/
wp-content/wp-cache-config.php

 

Published by

Andy Brudtkuhl

Andy is a full stack web developer, growth hacker, entrepreneur, bike commuter, seinfeld enthusiast, and daddy to three little girls and two dogs in Iowa.

2 thoughts on “WordPress .gitignore”

  1. Hi, Andy. Nice ignore file. Do you tend to always ignore the plugins directory? How do you keep plugins in sync across live->staging, staging-live scenarios?

    1. Like I said in the post, my ignore strategy varies depending on the project and there is no right answer. Recently I’ve been moving towards keeping EVERYTHING in the repo (aside from wp-content/uploads and wp-config) for ease of deployment workflow.

Leave a Reply to Raoul Cancel reply

Your email address will not be published. Required fields are marked *