Take the 2-minute tour ×

I have a directory structure like this:


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/* #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 :)

share|improve this question
Probably somebody will find as helpful: if you have few repositories and each has the same .gitignore file, you can put it into "common" location and launch > git config --global core.excludesfile ~/.gitignore_global The last parameter is path to the common location. P.S. I'm new to git and not sure if that is 'best practice' recommendation. So please let me know if you should not want to do that. Thank you. –  Budda Nov 28 '11 at 2:04
The ** syntax seems now (March 2013, git 1.8.2) officially documented: see my answer below –  VonC Apr 23 '13 at 9:21
add comment

6 Answers

up vote 464 down vote accepted

I've no idea where the impression that ** has any special meaning in a .gitignore pattern comes from. It's not mentioned in the gitignore man page or the fnmatch man page which the gitignore man page refers to.

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:


This should be pretty clear from the gitignore man page. There's even an example of ignoring a directory called foo using an analogous pattern.

share|improve this answer
Yep, I read the man page, I just assumed the foo/ example meant relative to the .gitignore file (or root if not in a .gitignore), I didn't realise it could be anywhere. bin/ is exactly right, hacker suggested it in a comment and I discovered it when replying to Mark, but yours is an answer so I shall accept it. And I won't accept my own since it's a bit over-the-top ;) –  Ben Hymers Sep 24 '09 at 9:41
I don't believe that any answer on your linked question has fully answered the issue. fnmatch is a standard POSIX function so it is reasonable for git to use the defined behaviour of fnmatch in its ignore implementation. It does mean that git is open to portability issues on platforms that supply a non-standard fnmatch implementation, though. –  Charles Bailey Sep 24 '09 at 9:59
Suppose I want to ignore foo/output/ at any depth, but not bar/output/ ? Based on this answer, I would have thought simply foo/output/ would work, but it doesn't. –  Julian Mann Jan 24 '12 at 2:18
@JulianMann: No, it's not supposed to work. Because foo/output/ contains a / (other than the trailing /) it is treated as patch for a fnmatch style matching and won't match at lower directory levels. –  Charles Bailey Jan 24 '12 at 8:01
Starting with git 1.8.2, git will accept ** in .gitignore files (source: 1.8.2 changelog) –  Carlos Campderrós Feb 18 '13 at 10:58
show 5 more comments

The .gitignore of your dream seems to be:


on the top level.

share|improve this answer
You're a genius :) That worked, but I don't want to ignore files and directories that have 'bin' as part of their names, sorry. I've added that to the question description, but you still get a vote up :) –  Ben Hymers Sep 24 '09 at 9:20
But it will not get files that have bin as a part of their names ignored. I didn't say *bin*, did I? –  Michael Krelin - hacker Sep 24 '09 at 9:24
The only drawback is that it will ignore bin files, not only directories. I can't tell right out of my head whether using bin/ will cure that, but it may. –  Michael Krelin - hacker Sep 24 '09 at 9:26
Yep, bin/ works, you get an extra vote up for your comment ;) –  Ben Hymers Sep 24 '09 at 9:43
Heh, thanks Bombe, now the '/' is in the answer ;-) –  Michael Krelin - hacker Sep 24 '09 at 13:35
show 1 more comment

The ** never properly worked before, but since git 1.8.2 (March, 8th 2013), it seems to be explicitly mentioned and supported:

The patterns in .gitignore and .gitattributes files can have **/, as a pattern that matches 0 or more levels of subdirectory.

E.g. "foo/**/bar" matches "bar" in "foo" itself or in a subdirectory of "foo".

In your case, that means this line might now be supported:

share|improve this answer
@BenHymers I didn't test it yet, so let me know if it is working ;) –  VonC Apr 23 '13 at 11:38
Note to self: see also stackoverflow.com/a/20391855/6309 –  VonC Dec 5 '13 at 6:50
add comment

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.

share|improve this answer
This isn't an answer to the original question which was explicitly about bin, not Bin. –  Charles Bailey Oct 9 '09 at 7:08
Though not an answer, it does add to the completeness for others searching on the same issue (myself, just now). –  Jay Jan 12 '10 at 19:44
add comment

matches both upper and lower case

share|improve this answer
add comment

I recommend using the gitignore templates here: https://github.com/github/gitignore

The Visual Studio gitignore will ignore the bin file but not any tools you add.


share|improve this answer
add comment

Your Answer


