GoranStimac.com
How Can I Help
Stay Informed
Let's Connect

©2018 - 2021 Goran Štimac. All rights reserved.
v1.28_b2021-09-14

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.

 1# -----------------------------------------------------------------
 2# By default all files are ignored.  You'll need to whitelist
 3# any mu-plugins, plugins, or themes you want to include in the repo.
 4#
 5# To ignore uncommitted changes in a file that is already tracked, use 
 6# git update-index --assume-unchanged
 7#
 8# To stop tracking a file that is currently tracked, use 
 9# git rm --cached
10# -----------------------------------------------------------------
11
12# ignore everything in the root except the "wp-content" directory.
13/*
14!wp-content/
15
16# ignore everything in the "wp-content" directory, except:
17# mu-plugins, plugins, and themes directories
18wp-content/*
19!wp-content/mu-plugins/
20!wp-content/plugins/
21!wp-content/themes/
22
23# ignore all mu-plugins, plugins, and themes
24# unless explicitly whitelisted at the end of this file
25wp-content/mu-plugins/*
26wp-content/plugins/*
27wp-content/themes/*
28
29# ignore all files starting with . or ~
30.*
31~*
32
33# ignore node dependency directories (used by grunt)
34node_modules/
35
36# ignore OS generated files
37ehthumbs.db
38Thumbs.db
39
40# ignore Editor files
41*.sublime-project
42*.sublime-workspace
43*.komodoproject
44
45# ignore log files and databases
46*.log
47*.sql
48*.sqlite
49
50# ignore compiled files
51*.com
52*.class
53*.dll
54*.exe
55*.o
56*.so
57
58# ignore packaged files
59*.7z
60*.dmg
61*.gz
62*.iso
63*.jar
64*.rar
65*.tar
66*.zip
67
68# -------------------------
69# BEGIN Whitelisted Files
70# -------------------------
71
72# track these files, if they exist
73!.gitignore
74!.editorconfig
75!.phpcs.xml.dist
76!README.md
77!CHANGELOG.md
78!composer.json
79
80# track favicon files, if they exist
81!android-chrome-*.png
82!apple-touch-icon*.png
83!browserconfig.xml
84!favicon*.png
85!favicon*.ico
86!manifest.json
87!mstile-*.png
88!safari-pinned-tab.svg
89!site.webmanifest
90
91# track these mu-plugins, plugins, and themes
92# add your own entries here
93!wp-content/mu-plugins/example-mu-plugin/
94!wp-content/plugins/example-plugin/
95!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.

Share:

comments powered by Disqus
Hostinger Affiliate

Let’s Talk About Your Needs

Free Consultation