In fact, you can make it a little more elegant. The following should work for you. Just remember the directories, you need to add ** at the end of the template to include all the files in it, but not only the directory itself.
src # for directories !src/wp-content/themes/chocolat-child/** # for files !src/wp-content/themes/othertheme
If you also want to ignore all files / directories outside the src directory, do this as follows.
* !*/ # for directories !src/wp-content/themes/chocolat-child/** # for files !src/wp-content/themes/othertheme
To understand the reasons, see my answer to the SO question . In general, there are 2 rules for the negation pattern in .gitignore .
Rule 1. Files and directories are separated from each other in templates. To include a reverse directory does not mean that its child files / directories are also included back.
Rule 2. It will not include files / directories if their parent directory is still ignored.
source share