From https://stackoverflow.com/questions/2545602/how-to-git-ignore-subfolders-subdirectories

To ignore Solutions/projects/bin/Debug but not bin/Debug

Solution/*/bin/Debug

you can also use the ** wildcard to match any level of subdirectories:

**/bin/Debug/

Bonus Content: Remove existing git tracked files

Now say you had a folder (commited to your git repository) that you now wanted to remove altogether from your repository. First add it to your gitignore file. Then do one of the following steps.

https://stackoverflow.com/questions/7075923/resync-git-repo-with-new-gitignore-file

  1. Extreme

    git rm -r --cached
    git add .
    git commit -m "Updated .gitignore"
    
  2. Controlled (didn’t work for me last time around):

    git rm --cached `git ls-files -i --exclude-standard`