Search code examples
wordpressgitgitignore

Exclude auto-generated image sizes in WordPress uploads folder with gitignore


I have a directory structure similar to bedrock. So WordPress in its own subdirectory wp/ and the stuff that normally goes into wp-content is in app/. I want to exclude all directories in app/ BUT uploads/.

But inside uploads/ itself I want to exclude every image that was automatically generated by WordPress. So every file that follows the pattern $original_image_name-$widthx$height.$ext.

I tried the different solutions from all the already asked questions there are and my current (still not working) .gitignore looks like this now:

.gitignore

# WordPress
public/wp/
public/app/*
!public/app/uploads
public/app/uploads/*-*x*.* # auto-generated sizes

When checking git status public/app/uploads/ it still shows the auto-generated files as Untracked files along with the other images.


Solution

  • The error actually just was that I added the # comment in the same line as the pattern..

    So what I got now is

    .gitignore

    public/wp/
    public/app/*
    !public/app/uploads/
    public/app/uploads/*-*x*.*