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.
- # Configuration.
- /.htaccess
- /wp-config.php
- # Sitemap files.
- /sitemap.xml
- /sitemap.xml.gz
- # Files in the root.
- *.pdf
- *.jpg
- *.jpeg
- *.png
- *.txt
- *.csv
- # WP dirs.
- wp-admin/*
- wp-includes/*
- wp-snapshots/*
- # Ignore everything in the "wp-content" directory, except custom code.
- /wp-content/languages/*
- /wp-content/uploads/*
- /wp-content/plugins/*
- !wp-content/plugins/CUSTOM_PLUGIN_1
- !wp-content/plugins/CUSTOM_PLUGIN_2 # etc.
- /wp-content/themes/*
- !wp-content/themes/CUSTOM_THEME_1
- !wp-content/themes/CUSTOM_THEME_2 # etc.
- # Ignore node dependency directories.
- **/node_modules/
- # Ignore log files and databases.
- *.log
- *.sql
- *.sqlite
- # PhpStorm files.
- /.idea/
- # DS_Store files generated by Finder on MacOS.
- **/.DS_Store