ignoring any 'bin' directory on a git project
I have a directory structure like this:
.git/ .gitignore main/ ... tools/ ... ...
Inside main and tools, and any other directory, at any level, there can be a 'bin' directory, which I want to ignore (and I want to ignore everything under it too). I've tried each of these patterns in .gitignore but none of them work:
/**/bin/**/* /./**/bin/**/* ./**/bin/**/* **/bin/**/* */bin/**/* bin/**/* /**/bin/* #and the others with just * at the end too
Can anyone help me out? The first pattern (the one I think should be working) works just fine if I do this:
But I don't want to have an entry for every top-level directory and I don't want to have to modify .gitignore every time I add a new one.
This is on Windows using the latest msysgit.
EDIT: one more thing, there are files and directories that have the substring 'bin' in their names, I don't want those to be ignored :)
Before version 1.8.2,
** didn't have any special meaning in the
.gitignore. As of 1.8.2 git supports
** to mean zero or more sub-directories (see release notes).
The way to ignore all directories called bin anywhere below the current level in a directory tree is with a
.gitignore file with the pattern:
man page, there an example of ignoring a directory called
foo using an analogous pattern.
If you already have any bin folders in your git index which you no longer wish to track then you need to remove them explicitly. Git won't stop tracking paths that are already being tracked just because they now match a new
.gitignore pattern. Execute a folder remove (rm) from index only (--cached) recursivelly (-r). Command line example for root bin folder:
git rm -r --cached bin
Read more… Read less…
.gitignore of your dream seems to be:
on the top level.
I think it is worth to mention for git beginners:
If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:
git rm --cached
So if you want add to ignore some directories in your local repository (which already exist) after editing .gitignore you want to run this on your root dir
git rm --cached -r . git add .
It will basically 'refresh' your local repo and unstage ignored files.
** never properly worked before, but since git 1.8.2 (March, 8th 2013), it seems to be explicitly mentioned and supported:
The patterns in
.gitattributesfiles can have
**/, as a pattern that matches 0 or more levels of subdirectory.
foo/**/bar" matches "
bar" in "
foo" itself or in a subdirectory of "
In your case, that means this line might now be supported:
matches both upper and lower case
I didn't see it mentioned here, but this appears to be case sensitive. Once I changed to /Bin the files were ignored as expected.