How can I help

Stay informed and learn

Let's connect

Git ignore for WordPress projects

My preferred .gitignore file appears below and it ignores everything by default. This allows me to whitelist only those plugins and themes I wish to include in my repo.

While I use this .gitignore for WordPress projects, for stand-alone plugins or themes I use a general .gitignore.

# -----------------------------------------------------------------
# By default all files are ignored.  You'll need to whitelist
# any mu-plugins, plugins, or themes you want to include in the repo.
# 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
# -----------------------------------------------------------------

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

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

# ignore all mu-plugins, plugins, and themes
# unless explicitly whitelisted at the end of this file

# ignore all files starting with . or ~

# ignore node dependency directories (used by grunt)

# ignore OS generated files

# ignore Editor files

# ignore log files and databases

# ignore compiled files

# ignore packaged files

# -------------------------
# BEGIN Whitelisted Files
# -------------------------

# track these files, if they exist

# track favicon files, if they exist

# track these mu-plugins, plugins, and themes
# add your own entries here

Why exclude most files?

I update plugins on the server using the built-in WordPress update functionality. When a plugin is updated on a server in this way, it becomes out of sync with the Git repo. The particular situation I want to avoid is pushing an outdated version of a plugin from my local machine to the live site.

This same argument applies to WordPress core and theme files.

What I include

I only include plugins and themes that are specific to the project. For example, if I’m creating a custom theme for the project, the theme gets included in the repo. If I write a plugin specific to this project, it gets included in the repo.

What I don’t include

Any plugin or theme that lives somewhere else is not included in the repo. Some examples include:

  • a plugin available in the WordPress.org repo
  • a parent theme
  • a plugin that includes its own update routine

Keeping Track of Plugins

Since I don’t include most plugins in my Git repo, it is helpful to keep a list of them for creating a new copy of the project. While this can be a simple list of plugins to install, but you can also use Composer to do this automatically.

Newer post

Drupal 10 will change how you create themes with new starter kit

Older post

New opportunity for creators and businesses - YouTube Shorts

comments powered by Disqus

Looking for an IT professional?

Book a call Email me