WordPress + Git – .gitignore file

The purpose of this post is to parse what should be ignored using the .gitignore file when tracking WordPress projects with GIT

(credit to Steve Grunwell for large parts of this, he wrote an excellent article here)


# Keep these files out of the repo

# Hidden files


Why keep uploads out of the repo?

  • As soon as a file is uploaded by a user or client the repo will be out of date.
  • Uploads + Thumbnails = heavy repo w/ no benefit

The better way:

<IfModule mod_rewrite.c>
  RewriteEngine on

  # Attempt to load files from production if
  # they're not in our local version
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule wp-content/uploads/(.*) \
    http://{PROD}/wp-content/uploads/$1 [NC,L]

This snippet checks to see if the requested file exists in the local file system and does the following:

  • Yes: Load it like normal
  • No: Attempt to load the file from production

That means no more FTP-ing files to your dev/staging environments.

This snippet would live in your .htaccess file

Create a fresh wp-config.php file:

$ git clone {REPO} {DIRECTORY}
$ cp wp-config-sample.php wp-config.php
$ vi wp-config.php

Put it all together:

  1. Clone repository
  2. Import database
  3. Fill out wp-config.php
  4. Setup virtual host (if necessary)

Additional Tips:

Has anything changed on the target server?

Add to deployment script to ensure nothing has changed on server:

$ git ls-files -dmo --exclude-standard

Will be empty if there are unchanged files, easier than parsing git status


There is also a popular gist on this at github:



Best Web Development Resources 2016

SSH Key Tutorial – Setting up an SSH tunnel so you can download a Git Repository from