Wordpress + Git: What to include in your .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

*.DSStore *Thumbs.db _.sass-cache ~imageoptim

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:

# -----------------------------------------------------------------
# .gitignore for WordPress
# Bare Minimum Git
# http://ironco.de/bare-minimum-git/
# ver 20150227
# This file is tailored for a WordPress project 
# using the default directory structure
# This file specifies intentionally untracked files to ignore
# http://git-scm.com/docs/gitignore
# The purpose of gitignore files is to ensure that certain files not
# tracked by Git remain untracked.
# To ignore uncommitted changes in a file that is already tracked,
# use `git update-index --assume-unchanged`.
# To stop tracking a file that is currently tracked,
# use `git rm --cached`
# Change Log:
# 20150227 Ignore hello.php plugin. props @damienfa
# 20150227 Change theme ignore to wildcard twenty*. props @Z33
# 20140606 Add .editorconfig as a tracked file
# 20140404 Ignore database, compiled, and packaged files
# 20140404 Header Information Updated
# 20140402 Initially Published
# -----------------------------------------------------------------

# ignore everything in the root except the "wp-content" directory.

# ignore all files starting with .

# track this file .gitignore (i.e. do NOT ignore it)

# track .editorconfig file (i.e. do NOT ignore it)

# track readme.md in the root (i.e. do NOT ignore it)

# ignore all files that start with ~

# ignore OS generated files

# ignore Editor files

# ignore log files and databases

# ignore compiled files

# ignore packaged files

# ignore everything in the "wp-content" directory, except:
# "mu-plugins" directory
# "plugins" directory
# "themes" directory

# ignore these plugins

# ignore specific themes

# ignore node/grunt dependency directories