You are developing a new WordPress site.
You create a new Git repository for it.
You’re wondering how to structure the gitignore file.
In most cases, there is no reason to include the WordPress core files in the project repository. WordPress already has its own Git repository and as an open source project, it is, of course, public.
There is usually no need to track changes in third-party plugins and themes either. They are also updated by external developers, and modifying external plugins yourself is not a best practice.
On the other hand, we do want our developments (custom plugins, themes, etc.) to be under version control.
A gitignore template for WordPress
A few years ago I found this great gitignore template for WordPress projects by redoPop.
The way it works is by excluding all the files and folders, starting from the root folder. Then, including (by adding !
before the path) only the things we want, bit by bit.
I find this gitignore technique useful for most of my WordPress development projects. It makes the .gitignore
file of WordPress projects simple, clear, and very easy to manage.
Make it even better
Another tip for further improving this technique: Use the project name as a prefix.
Suppose we are working on a WordPress project that contains many custom plugins that we develop ourselves.
We’d like to include these plugins in our Git repository so we can keep track of changes.
To keep it simple and organized, we will include the project name at the beginning of the folder names of those plugins.
For instance,
notesontech-carousel
notesontech-login
(Replace notesontech
with your project name).
We can then automatically include all the plugin folders that start with the project name in our Git repository:
wp-content/plugins/*
!wp-content/plugins/notesontech-*
This way, when creating a new custom plugin in the future, we simply add the project prefix to the folder name and it will be automatically included in Git.
There is no need to modify the .gitignore
file for each new plugin.
Must-use plugins
Another customization I usually make to this gitignore template is to add the same logic to the must-use plugins, right after the regular plugins section:
wp-content/mu-plugins/*
!wp-content/mu-plugins/notesontech-*