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.

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.

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.

One last thing…

If you liked this article, I'd be incredibly grateful if you tweeted about it.

Also, I don't send emails often but when I do, I try to fill them full of useful goodies. If you like code snippets & dev tips, join my mailing list. There's no catch but I'll probably want to tell you about any new plugins & tools I build.