How to remove Git tracking for third party plugins in WordPress

When I work on custom WordPress builds, it tends to be a collection of a theme, one or more custom plugins, and a series of third party plugins. For this reason, I usually opt to track the entire wp-content directory in a single Git repository.

Sometimes it makes sense to track third party plugins but often, I prefer not to and in some cases, I’ve even changed my mind and had to remove tracking. Here’s how I go about it.

Ignore all third party plugins, allow tracking of custom plugins

First up, we need to ignore anything within the /plugins directory but allow continued tracking of any plugins that have a particular prefix. Add this to the .gitignore file. This combination of rules ensures that any plugins I create prefixed with hookturn- will continue to track in the repo. Use a prefix appropriate to your project.

# Ignore all plugins
/plugins/*
# Allow tracking of plugins with our custom prefix
!/plugins/hookturn*

Remove the unwanted files from the repo

Next, we use a command to remove all the files from Git. This removes all files from the /plugins directory. Note that this doesn’t delete the files from the project – only from the Git repo.

git rm -r –cached plugins
view raw remove.sh hosted with ❤ by GitHub

Commit the changes

Now we just need to commit the changes. This commit will have the changes to the .gitignore file as well as the files from plugins we still want to track.

git commit -m "Stopped tracking third party plugins"
view raw commit.sh hosted with ❤ by GitHub

Need a website? Let's talk.

From website design & SEO through to custom WordPress plugin development. I transform ideas into dynamic, engaging, and high-performing solutions.
Subscribe to get the latest insights & updates in the world of web and how it impacts your business and website.
© 2024 Phil Kurth  |  All rights reserved.