As s code repository GitHub has a lot to offer to software developers: it is a place to publish and share our code, a repository from where we can download third party libraries to incorporate to our own solutions, and also an useful tool for learning.

If there is an open source library that we want to use in your projects chances are that it has is own page in GitHub: we can therefore download it and read its code. But at times we are interested in something else: finding examples on how a certain library it is used in real life projects. In other words we would like to find projects in GitHub that use a certain library.

Let´s see how to do that, and as an example let´s find GitHub projects that use the NSubstitute library.

It will be nice if the GitHub´s advanced search had an option to filter projects that use certain libraries, but although at this time that option does not exist we can still achieve that goal using the available search options.

Do a code Search filtering by programming language

Imagine that we want to find C# projects that use the NSubstitute library: we know that a C# project using a certain library will commonly contain the line using namespace; in various of its files. So if do a code search – filtering by the C# language – of a statement such as “using Nsubstitute;” we would get a list of projects using that library.
github search by code filtering by C# language
Notice that in order to use the code search we need to log into our GitHub account.

Narrow your search by excluding repositories

The search above has returned various results that are not very interesting: the first page for example contains multiple references to the repository nsubstitute/NSubstitute.Analyzers; in other words: the NSubstitute repository itself. Not a very interesting result if we are looking for external projects making use of the library in question.

We can narrow our search by excluding such repositories adding repository filters to our search.

"using Nsubstitute;"  -repo:nsubstitute/NSubstitute.Analyzers

Following the previous steps we can obtain a basic list of projects that make use of a certain library. From this point we can keep refining our search – adding extra filters or search terms – to obtain more specific results. The GitHub search help has extensive information on how to use the different GitHub search options.