My issue is that I have a bunch of WordPress websites in my git repo, of which I want to selectively commit only the content of my
root (git repo)
- / wordpress
- - / (WordPress Site 1)/wp-content/themes
- - / (WordPress Site 2)/wp-content/themes
- - / (WordPress Site 3)/wp-content/themes
# Ignore everything:
# Except for wordpress themes:
Here's how I did it - you essentially have to walk up the paths, you can't wildcard more than one level in any direction:
# Ignore everything: * # Except for the themes directories: !wordpress/ !wordpress/*/ !wordpress/*/wp-content/ !wordpress/*/wp-content/themes/ !wordpress/*/wp-content/themes/* !wordpress/*/wp-content/themes/*/* !wordpress/*/wp-content/themes/*/*/* !wordpress/*/wp-content/themes/*/*/*/* !wordpress/*/wp-content/themes/*/*/*/*/*
Notice how you have to explicitly allow content for each level you want to include. So if I have subdirectories 5 deep under themes, I still need to spell that out.
This is only how it worked for me. If someone cares to offer a more informed explanation by all means.
NOTE: I tried using double-wildcard 'globs' but according to this that functionality is system dependent and it didn't work on my mac:
Did NOT work: