Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+4 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

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:

/main/**/bin/**/*

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 :)

1 Answer

+4 votes
by (27.5k points)
edited by

Before version 1.8.2, ** didn't have any special meaning in the .gitignore. As of git version 1.8.2, it supports ** to mean zero or more sub-directories.

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:

bin/

In the main page, there an example of ignoring a directory called foo using an analogous pattern.

If you have any bin folders already in your git index which you no longer wish to keep track of then you need to remove them explicitly. Git will not stop keep track of 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

I have found this tutorial for learning all concepts of git hope this helps for you:

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...