Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ignoring any 'bin' directory on a git project

Tags:

git

gitignore

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

like image 284
Ben Hymers Avatar asked Sep 24 '09 09:09

Ben Hymers


People also ask

How do I ignore a folder in Git repository?

If you want to maintain a folder and not the files inside it, just put a ". gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository.

How do I ignore unwanted files in git?

To avoid having to ignore unwanted files manually, you can create a . gitignore file in the working directory of your project. Inside this file, you can specify simple patterns that Git will use to determine whether or not a file should be ignored.

Should you ignore .GIT folder?

The entire vendor folder should be ignored, not just the . git sub-directories. Which packages are used are stored in composer. json and composer.


1 Answers

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:

bin/ 

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

Edit: 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 
like image 92
CB Bailey Avatar answered Sep 22 '22 13:09

CB Bailey