I know it's an old post, but I was still having this problem, and using MsysGit 1.8.0, I was not able to use the accepted answer by @manojlds.
It seems the only patterns that exclude all bin folders at any depth are [Bb]in
and [Bb]in/
. According to the gitignore man page, the one with the trailing slash is most correct, since it will only match directories, and not files named "bin". As soon as I try to add additional levels to the pattern, such as [Bb]in/*
, this ceases to match at any depth and becomes relative to the location of the .gitignore file, as per the man page.
Now, assuming that I have a [Bb]in/
entry in my global .gitignore file, the best way I found to unignore a specific pattern of files (like .refresh files) in a specific bin folder is to create another .gitignore file one directory above the bin folder (i.e., the project's directory) and in it place the following entries:
![Bb]in/
[Bb]in/*
![Bb]in/*.refresh
Our web site project bin folders never contain sub folders like Debug or Release, but I tested and this still ignores subfolders in the bin folder, as desired.
If I only use the second and third entries, as seemed suggested by the accepted answer, it doesn't work. An intuitive explanation is that the first entry removes this specific bin folder from the global glob, so its contents will be included, then the second entry works as desired since it is relative to the .gitignore file in this case, and the third entry removes the desired patterns from the glob created by the second entry.