Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git ignore subfolders / subdirectories?

I have a lot of projects in my .Net solution. I would like to exclude all "bin/Debug" and "bin/Release" folders (and their contents), but still include the "bin" folder itself and any dll's contained therein.

.gitignore with "bin/" ignores "Debug" and "Release" folders, but also any dll's contained in the "bin" folder.

bin/Debug or bin/Release in the .gitignore file does not exclude the directories unless I fully qualify the ignore pattern as Solution/Project/bin/Debug - which I don't want to do as I will need to include this full pattern for each project in my solution, as well as add it for any new projects added.

Any suggestions?

like image 215
Marcel Avatar asked Mar 30 '10 13:03

Marcel


People also ask

Does Gitignore working in subfolder?

gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.


2 Answers

Have you tried wildcards?

Solution/*/bin/Debug Solution/*/bin/Release 

With version 1.8.2 of git, you can also use the ** wildcard to match any level of subdirectories:

**/bin/Debug/ **/bin/Release/ 
like image 136
Josh Lee Avatar answered Sep 25 '22 13:09

Josh Lee


You can use .gitignore in the top level to ignore all directories in the project with the same name. For example:

Debug/ Release/ 

This should update immediately so it's visible when you do git status. Ensure that these directories are not already added to git, as that will override the ignores.

like image 24
Andreas Avatar answered Sep 21 '22 13:09

Andreas