Skip to content

Instantly share code, notes, and snippets.

@jasewarner
Last active October 2, 2024 08:22
Show Gist options
  • Save jasewarner/0b4baf4d0fc2388039e73722cc7fcee2 to your computer and use it in GitHub Desktop.
Save jasewarner/0b4baf4d0fc2388039e73722cc7fcee2 to your computer and use it in GitHub Desktop.
WordPress project .gitignore
# ignore everything in the root except the "wp-content" directory.
/*
!wp-content/
# ignore everything in the "wp-content" directory, except the themes directories
wp-content/*
!wp-content/themes/
# ignore all mu-plugins, plugins, and themes
# unless explicitly whitelisted at the end of this file
wp-content/themes/*
# ignore all files starting with . or ~
.*
~*
# ignore node dependency directories (used by grunt)
node_modules/
# ignore OS generated files
ehthumbs.db
Thumbs.db
# ignore Editor files
*.sublime-project
*.sublime-workspace
*.komodoproject
*.codekit3
.idea
# ignore log files and databases
*.log
*.sql
*.sqlite
# ignore compiled files
*.com
*.class
*.dll
*.exe
*.o
*.so
# ignore packaged files
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# -------------------------
# BEGIN Whitelisted Files
# -------------------------
# track these files, if they exist
!.gitignore
!.editorconfig
!.scss-lint.yml
!README.md
!CHANGELOG.md
!composer.json
# track these themes
!wp-content/themes/theme_name/
@thebigtine
Copy link

I would suggest adding *.codekit3

@mikedamoiseau
Copy link

I would add .idea to the list

@vanduc1102
Copy link

i want to ignore dist folder in my theme.
wp-content/themes/my-theme/dist
the dist is a result of webpack build

@thebigtine
Copy link

thebigtine commented Jun 16, 2020

i want to ignore dist folder in my theme.
wp-content/themes/my-theme/dist
the dist is a result of webpack build

@vanduc1102 use: wp-content/themes/my-theme/dist/*

@jasewarner
Copy link
Author

@mikedamoiseau, I've added .idea. Thanks for the suggestion.

@jasewarner
Copy link
Author

jasewarner commented Jun 16, 2020

@josephbydeign, a (very) belated thanks for the *.codekit3 suggestion and also for helping out @vanduc1102.

@thebigtine
Copy link

@jasewarner you're welcome 😄

@vanduc1102
Copy link

vanduc1102 commented Jun 16, 2020

it doesnt work @jose,
here is my code

wp-content/*
!wp-content/mu-plugins/

!wp-content/plugins/
wp-content/plugins/*
!wp-content/plugins/p-a/

!wp-content/themes/
wp-content/themes/*
!wp-content/themes/theme-a/
wp-content/themes/theme-a/dist/*
!wp-content/themes/theme-b/

After commit the .gitignore and run git update-index
I'm still seeing files in dist/* as tracked
------- UPDATED --------
my bad, the dist was tracked, I need to delete the dist folder and commit them,
the code above works well, thanks @josephbydeign

@michael-sumner
Copy link

For those of you having issues with the gitignore still not working. The reason is because the git has cached that gitignore.
So what you should do is clear the gitignore cache within your git installation, by doing so:

git rm --cached -r . && git add .

That way you can ensure that if you want to ignore a file but it is not working, then the reason is because gitignore has cached that file to still be present in your future commits. By clearing the gitignore cache you are able to effectively ignore the files to follow your gitignore.

Yes, I said gitignore 7 times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment