Skip to main content

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

/wp-content/themes/twenty*

/wp-content/upgrade

/wp-content/uploads

/sitemap.*

/wp-config.php

*.sql

Hidden files

*.DS_Store *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]
</IfModule>

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}
$ cd {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
#
# NOTES:
# 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.
/*
!wp-content/

# ignore all files starting with .
.*

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

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

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

# ignore all files that start with ~
~*

# ignore OS generated files
ehthumbs.db
Thumbs.db

# ignore Editor files
*.sublime-project
*.sublime-workspace
*.komodoproject

# ignore log files and databases
*.log
*.sql
*.sqlite

# ignore compiled files
*.com
*.class
*.dll
*.exe
*.o
*.so

# ignore packaged files
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

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

# ignore these plugins
wp-content/plugins/hello.php

# ignore specific themes
wp-content/themes/twenty*/

# ignore node/grunt dependency directories
node_modules/

Comments

Recent Work

Free desktop AI Chat client, designed for developers and businesses. Unlocks advanced model settings only available in the API. Includes quality of life features like custom syntax highlighting.

Learn More

BidBear

bidbear.io

Bidbear is a report automation tool. It downloads Amazon Seller and Advertising reports, daily, to a private database. It then merges and formats the data into beautiful, on demand, exportable performance reports.

Learn More