GoranStimac.com

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.
/*
!wp-content/

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

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

# ignore all files starting with . or ~
.*
~*

# ignore node dependency directories (used by grunt)
node_modules/

# 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

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

# track these files, if they exist
!.gitignore
!.editorconfig
!.phpcs.xml.dist
!README.md
!CHANGELOG.md
!composer.json

# track favicon files, if they exist
!android-chrome-*.png
!apple-touch-icon*.png
!browserconfig.xml
!favicon*.png
!favicon*.ico
!manifest.json
!mstile-*.png
!safari-pinned-tab.svg
!site.webmanifest

# track these mu-plugins, plugins, and themes
# add your own entries here
!wp-content/mu-plugins/example-mu-plugin/
!wp-content/plugins/example-plugin/
!wp-content/themes/example-theme/

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