.gitignore file for WordPress development

Posted on 09/09/2019

For some reason there is no standardized WordPress .gitignore file that can be kept in the project root. After going back to my own boilerplates for 100th time, I figured I might as well post that here and on Github.

The code is below and Github repo is github.com/aramboyajyan/wordpress-gitignore. Rules work on the principle that they first exclude all plugins and themes, and then declare the directories with custom code that you want to keep under version control.

  1. # Configuration.
  2. /.htaccess
  3. /wp-config.php
  4.  
  5. # Sitemap files.
  6. /sitemap.xml
  7. /sitemap.xml.gz
  8.  
  9. # Files in the root.
  10. *.pdf
  11. *.jpg
  12. *.jpeg
  13. *.png
  14. *.txt
  15. *.csv
  16.  
  17. # WP dirs.
  18. wp-admin/*
  19. wp-includes/*
  20. wp-snapshots/*
  21.  
  22. # Ignore everything in the "wp-content" directory, except custom code.
  23. /wp-content/languages/*
  24. /wp-content/uploads/*
  25. /wp-content/plugins/*
  26. !wp-content/plugins/CUSTOM_PLUGIN_1
  27. !wp-content/plugins/CUSTOM_PLUGIN_2 # etc.
  28. /wp-content/themes/*
  29. !wp-content/themes/CUSTOM_THEME_1
  30. !wp-content/themes/CUSTOM_THEME_2 # etc.
  31.  
  32. # Ignore node dependency directories.
  33. **/node_modules/
  34.  
  35. # Ignore log files and databases.
  36. *.log
  37. *.sql
  38. *.sqlite
  39.  
  40. # PhpStorm files.
  41. /.idea/
  42.  
  43. # DS_Store files generated by Finder on MacOS.
  44. **/.DS_Store